### How to add days to date?

Posted:

**Thu Sep 20, 2012 7:12 pm**I am using two Calendar elements in my application one for start date and other for end date. 2 form variables that holds both values. I got difference of two dates in days. Say, for example

Start date is 09-20-2012 //(mm-dd-yyy)

End date is 09-24-2012

then no. of days would be 5 which is stored in some variable say "value"//Added some logic to get number of days

What I am doing is i am iterating until value is 5 and adding "value " to start date at each iteration. which is below

Somehow I am not able to get to add value 1 to startdate. Where I went wrong. Any suggestions.

Start date is 09-20-2012 //(mm-dd-yyy)

End date is 09-24-2012

then no. of days would be 5 which is stored in some variable say "value"//Added some logic to get number of days

What I am doing is i am iterating until value is 5 and adding "value " to start date at each iteration. which is below

- Code: Select all

for(var i-0;i<value;i++)

{

startdate.setDate(startdate.getDate()+i) ////stores original value in "startdate"

//some Code & store value in new record in table

//Result should be 09-20-2012, 09-21-2012 09-22-2012 // So on....

}

Somehow I am not able to get to add value 1 to startdate. Where I went wrong. Any suggestions.