Click to See Complete Forum and Search --> : how to increment the Date object in javascript


yu169409
10-22-2003, 08:36 AM
hi
i have a Date object in javascript, in a for loop, i need to increment the date by 1 day and do some condition checking, for example, the date object was initialized to Oct 1, 2003, for each loop, the date becomes Oct 2 2003, Oct 3, 2003 adn so on. how do i do the increment on Date object? just Date+1? thanks

Gollum
10-22-2003, 09:39 AM
if dt1 is your orignal date, then 24 hours after is...

var dt2 = new Date(dt1.getTime() + 86400000);

yu169409
10-22-2003, 10:47 AM
can i do something like this:
d1 = d1.setDate(d1.getDate()+1);
because i need to use d1 in the condition of a while loop

Charles
10-22-2003, 12:15 PM
dt1 = new Date(dt1.getTime() + 86400000)