Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Date Increment

Status
Not open for further replies.

SilverStray

Programmer
Oct 25, 2001
47
AU
Hi,

I have a page that will always get the next day and display it on screen. My problem is that, how do I increment a date to 1 calendar day? The following script of mine produces a date like 2/32/2005 if the current date is 1/31/2005, which is wrong.

var time=new Date();
var lmonth=time.getMonth()+1;
var date=time.getDate()+1;
var year=time.getYear();

defDate = lmonth + '/' + date + '/' + year;

Hope you can help.

Thanks in advance!

j. echavez
 
Code:
var time=new Date();
time.setTime(time.getTime() + 86400000);
will set time to be the current day plus the number of milliseconds that make up one day ... i.e. forward one day.
 
sorry, mine was silly, should just be:

Code:
var time = new Date();
time.setDate(time.getDate() + 1);
alert(time);

Not sure why you would try to re-invent the wheel.

*cLFlaVA
----------------------------
[tt]0101 is binary code for "supreme programmer of omnipotent power"[/tt] - adam0101
[URL unfurl="true"]http://www.coryarthus.com/[/url]
 
Not sure why you would try to re-invent the wheel.

Lack of trust, paranoia, call it what you will. The behaviour for setDate that you advocate works perfectly well, but is not specified in JavaScript up to 1.3. The behaviour for getTime is forcing to all eras of JS. Perhaps I'm just old.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top