How to add 1 day in javascript?

Hi

How can I add 1 day in javascript?

Why strDate2 show NaN?

var strDateEnd = frm.ctl01_txtEndDate.value;
var dnow	= new Date(frm.ctl01_txtEndDate.value);
var dend    = new Date(dnow + 1);
var strDate2 = dend;

Open in new window

techquesAsked:
Who is Participating?
 
ChristoferDutzConnect With a Mentor Commented:
Here is a dateToolbox to parse datestrings in any format.
http://www.mattkruse.com/javascript/date/
0
 
ChristoferDutzCommented:
Have a look at this ... hope it helps

http://www.adp-gmbh.ch/web/js/date/add_days.html
0
 
Sreedhar VengalaSr. Consultant - Business IntelligenceCommented:
Try this;


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

Open in new window

0
Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

 
techquesAuthor Commented:
alert(myDate); = NaN
alert(frm.ctl01_txtEndDate.value); = 2009-04-16
alert(strDate2); = NaN
var myDate = new Date(frm.ctl01_txtEndDate.value);
alert(myDate);
alert(frm.ctl01_txtEndDate.value);
var strDate2 = myDate.setDate(myDate.getDate()+1);
alert(strDate2);

Open in new window

0
 
ChristoferDutzCommented:
Well ... JavaScript couldn't parse your input.
Try:
Date.parse(datestring)
instead of
new Date(frm.ctl01_txtEndDate.value);
0
 
techquesAuthor Commented:
var myDate = Date.parse(frm.ctl01_txtEndDate.value);  //error, object not support this action
                  
alert(myDate); = NaN

var myDate = new Date.parse(frm.ctl01_txtEndDate.value);  //error, object not support this action

0
 
ChristoferDutzCommented:
Could you please post the format of the date being parsed?
0
 
techquesAuthor Commented:
alert(frm.ctl01_txtEndDate.value); = 2009-04-16

this format is fixed and cannot be changed as it need to pass to a SQL to do filtering
0
 
ChristoferDutzCommented:
Or you could use
var myDate = Date.UTC(year, month, day [, hrs] [, min] [, sec])

But here you would have to manually split upt the date into parts.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.