Solved

Adding days to any  date in javascript

Posted on 2014-02-04
7
239 Views
Last Modified: 2014-03-09
How to add 31 days to the date in JavaScript?
Both dates must be in format MM/DD/YY.
Thanks
0
Comment
Question by:niceguy971
7 Comments
 
LVL 33

Expert Comment

by:Big Monty
ID: 39833680
try this:

var today = new Date();
var newDay = new Date();
newDay.setDate(today.getDate()+31);

Open in new window

0
 

Author Comment

by:niceguy971
ID: 39833696
Hi Big Monty, it does  Not answer my question!!! The format must be MM/DD/YY
0
 
LVL 33

Accepted Solution

by:
Big Monty earned 500 total points
ID: 39833717
var today = new Date();
var newDay = new Date();
newDay.setDate(today.getDate()+31);

finalMonth = newDay.getMonth() + 1;
finalDay = newDay.getDate();
finalYear = newDay.getYear();

var result = finalMonth + '/' + finalDay + '/' + finalYear;

Open in new window

0
 
LVL 19

Expert Comment

by:Ken Butters
ID: 39833811
I think this would be simpler for the formatting part....

var newDay = new Date();
newDay.setDate(newDay.getDate()+31);

var result =newDay.format("mm/dd/yy");
0
 
LVL 9

Expert Comment

by:Sar1973
ID: 39835158
The getDate method will return a day between 1 and 31 (see http://www.w3schools.com/jsref/jsref_obj_date.asp).
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
Building a website can seem like a daunting task to the uninitiated but it really only requires knowledge of two basic languages: HTML and CSS.
In this tutorial viewers will learn how to position items using CSS's three positioning types Create a new HTML document with an internal stylesheet.: Create another div in CSS and name it Absolute : Type "position:absolute;" and "top:10px; left:50p…
In this tutorial viewers will learn how to embed an audio file in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: : The declaration should display (CODE) HTML5 is supported by the most recent versions of all major browsers…

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now