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
To get the previous month in moment js, use the subtract(1, "month") method to subtract the month in date and use format('MMMM') to get the month name from subtracted date. Just import moment in your file and call moment(). subtract(1, "month"). format('MMMM') and it will return previous month.
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')
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