I have a moment.js code that works well:
var startDate = '2015-05-06T19:00:00+0300';
moment(startDate).isBetween(moment(), moment().add(30, 'days'));
// returns true, that's great!
But when I start refactoring to make it more readable it fails to work:
var today = moment();
var startDate = '2015-05-06T19:00:00+0300';
moment(startDate).isBetween(today, today.add(30, 'days'));
// returns false.. but why?
MomentJS is a widely used time and date formatting and calculation library.
Mutability 1.0.The moment object in Moment. js is mutable. This means that operations like add, subtract, or set change the original moment object.
To get the current date and time, just call javascript moment() with no parameters like so: var now = moment();
var today = moment();
var startDate = '2015-05-06T19:00:00+0300';
moment(startDate).isBetween(today, moment(today).add(30, 'days'));
You are passing a reference which you have edited by adding 30 days.
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