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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Add a day onto today's date

Status
Not open for further replies.

KMarshall

Technical User
May 25, 2001
12
GB
Hi all, I'm simply trying to add 1 day onto today's date.
I've figured out that I need to convert todays date to milliseconds using getTime() but when I try to add 8640000 milliseconds (ie 1 day) onto my object I can't manage to convert it back so that the date is incremented by 1 day.

No doubt it's a doddle to to but I'm lost!
 
Hey KMarshall, try This:

NewDate = DateAdd("d", 1, Date)
 
Add 1 hour onto Now: DateAdd("h", 1, Now)

Add 2 Week onto "10/20/2004":
DateAdd("ww", 2, "10/20/2004")

....
 
Kendel,

DateAdd is VBScript, and this is a JavaScript forum, so it's probably not going to be too helpful.

KMarshall,

You're on the right track with adding the milliseconds. This should do the job for you:

Code:
myDate = new Date(myDate.getTime() + 86400000);

You were also missinng a 0 from the number 86400000 ;o)

Hope this helps,
Dan
 
Oops! I didn't get my coffee this morning. I'm going to get one now. :)
 
You could also do:

var d = new Date();
d.setDate(d.getDate() + 1);

*cLFlaVA
----------------------------
Lois: "Peter, you're drunk!"
Peter: "I'm not drunk, I'm just exhausted from stayin' up all night drinking!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top