Reputation: 117
I'm trying to find a way to add days to a moment. I can get it to work for a moment based on the current time, but that's it. Here my current code:
let start = moment('2017-01-15');
console.log(moment().add(7, 'days'));
console.log(moment(start).add(7, 'days'));
This is what get as the result:
Moment {_isAMomentObject: true, _isUTC: false, _pf: Object, _locale: Locale, _d: Mon Mar 13 2017 12:21:00 GMT-0400 (Eastern Daylight Time)…}
Moment {_isAMomentObject: true, _i: "2017-01-15", _f: "YYYY-MM-DD", _isUTC: false, _pf: Object…}
So it works on moment() but not that's it. Everywhere I look, that's how I'm supposed to do it so I don't know what I'm missing.
Upvotes: 3
Views: 12234
Reputation: 2928
You already created the moment
object, now you can call add
with start
variable.
let start = moment('2017-01-15');
console.log(moment().add(7, 'days'));
console.log(start.add(7, 'days'));
.as-console-wrapper {
top: 0;
max-height: 100% !important;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.17.1/moment.min.js"></script>
Upvotes: 8