how to get previous month first day and future month last day using moment.js,Please guide me with the relevant script required to achieve this
-
2I'm voting to close this question as off-topic because this is neither a code-writing nor tutorial service– jonrsharpeCommented Dec 14, 2015 at 20:11
-
Could you provide us with the code you have tried so far, and where you are getting hung up?– entropicCommented Dec 14, 2015 at 20:14
Add a comment
|
2 Answers
try something like
var prevMonthFirstDay = new moment().subtract(1, 'months').date(1)
and
var nextMonthLastDay = new moment().add(2, 'months').date(0)
or more verbose:
prevMonthFirstDay : moment().subtract(1, 'months').startOf('month')
nextMonthLastDay: moment().add(1, 'months').endOf('month')
-
1This answer is better cause it reset the time to 0:00:00, which is easier to compare between dates.– LayCommented Jul 6, 2020 at 7:44