This question already has an answer here:
- Add days to JavaScript Date 37 answers
I need to be able to add 1, 2 , 5 or 10 days to today's date using jQuery.
This question already has an answer here:
I need to be able to add 1, 2 , 5 or 10 days to today's date using jQuery.
Moment.js
Install
moment.js
from here.npm :
$ npm i --save moment
Bower : $
bower install --save moment
Next,
Link Ref : http://momentjs.com/docs/#/manipulating/add/
Moment.js
is an amazing Javascript library to manage Date objects and extremely light weight at40kb
.Good Luck.
I found that JavaScript can return a correct date when you use
new Date(nYear, nMonth, nDate);
with the over days of that month. Try to see the result of adDate
variable when you use this:var dDate = new Date(2012, 0, 34); // the result is 3 Feb 2012
I have a SkipDate function to share:
This is for 5 days:
You don't need JQuery, you can do it in JavaScript, Hope you get it.
The accepted answer here gave me unpredictable results, sometimes weirdly adding months and years.
The most reliable way I could find was found here Add days to Javascript Date object, and also increment month
EDIT: Even though it has worked for some people, I don't think it is entirely correct. I would recommend going with a more popular answer or using something like http://momentjs.com/
You can use JavaScript, no jQuery required:
Formatting to
dd/mm/yyyy
: