• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1011
  • Last Modified:

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

0
techques
Asked:
techques
  • 5
  • 3
1 Solution
 
ChristoferDutzCommented:
Have a look at this ... hope it helps

http://www.adp-gmbh.ch/web/js/date/add_days.html
0
 
Sreedhar VengalaCommented:
Try this;


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

Open in new window

0
 
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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:
Here is a dateToolbox to parse datestrings in any format.
http://www.mattkruse.com/javascript/date/
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

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

  • 5
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now