Solved

Adding days to any  date in javascript

Posted on 2014-02-04
7
234 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 32

Expert Comment

by:Big Monty
Comment Utility
try this:

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

Open in new window

0
 

Author Comment

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

Accepted Solution

by:
Big Monty earned 500 total points
Comment Utility
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
Comment Utility
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
Comment Utility
The getDate method will return a day between 1 and 31 (see http://www.w3schools.com/jsref/jsref_obj_date.asp).
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
In this Micro Tutorial viewers will learn how to create navigation buttons that change on rollover, using CSS (Continuation of the CSS Image Sprite tutorial) Create a parent ID for all the list items       - Specify position: absolute and display: block…
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

762 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

12 Experts available now in Live!

Get 1:1 Help Now