17

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

2
  • 2
    I'm voting to close this question as off-topic because this is neither a code-writing nor tutorial service
    – jonrsharpe
    Commented 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?
    – entropic
    Commented Dec 14, 2015 at 20:14

2 Answers 2

24

try something like

var prevMonthFirstDay = new moment().subtract(1, 'months').date(1)

and

var nextMonthLastDay = new moment().add(2, 'months').date(0)
19

or more verbose:

prevMonthFirstDay : moment().subtract(1, 'months').startOf('month')

nextMonthLastDay: moment().add(1, 'months').endOf('month')
1
  • 1
    This answer is better cause it reset the time to 0:00:00, which is easier to compare between dates.
    – Lay
    Commented Jul 6, 2020 at 7:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.