Having trouble adding days to moment js objects:
I'm using this code:
var contractMoment = this.moment(contract,'DD/MM/YYYY')
var start = contractMoment;
var end = contractMoment;
start = contractMoment.add(19, 'days');
end = contractMoment.add(51, 'days');
contractMoment looks like this before I add:
Thu Dec 02 2004 00:00:00 GMT-0600 (Central Standard Time)
and after I do the adding and console log start and end, here is what I'm getting:
Thu Dec 02 2004 00:00:00 GMT-0600 (Central Standard Time)
It returns a moment object for each, what am I missing here? is the added date buried somewhere in the moment object?
The add() method doesn't return a new moment. It modifies the moment and returns it. You need to create copies:
var contractMoment = moment(contract, 'DD/MM/YYYY');
var start = moment(contractMoment).add(19, 'days');
var end = moment(contractMoment).add(51, 'days');
See http://plnkr.co/edit/PgQuFARXGUB4fxUOxEYN?p=preview for a demo.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With