i have a start date string "20.03.2014" and i want to add 5 days to this with moment.js but i don't get the new date "25.03.2014" in the alert window.
here my javascript Code:
startdate = "20.03.2014";
var new_date = moment(startdate, "DD-MM-YYYY").add("DD-MM-YYYY", 5);
alert(new_date);
here my jsfiddle: http://jsfiddle.net/jbgUt/1/
How can i solve this ?
I like this string format "25.03.2014"
Hope someone can help me.
has to format and then convert to moment again.
You can reduce what they said in a few lines of code:
The function add() returns the old date, but changes the original date :)
var todayDate = moment().format('DD-MM-YYYY');//to get today date 06/03/2018 if you want to add extra day to your current date
thenvar dueDate = moment().add(15,'days').format('DD-MM-YYYY')// to add 15 days to current date..
point 2 and 3 are using in your jquery code...
UPDATED: January 19, 2016
As of moment 2.8.4 - use
.add(5, 'd')
(or.add(5, 'days')
) instead of.add('d', 5)
Thanks @Bala for the information.
UPDATED: March 21, 2014
This is what you'd have to do to get that format.
Here's an updated fiddle
ORIGINAL: March 20, 2014
You're not telling it how/what unit to add. Use -