Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to get previous month first day and future month last day using moment.js

Tags:

momentjs

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

like image 732
user1484535 Avatar asked Dec 14 '15 20:12

user1484535


People also ask

How can I get previous month in moment?

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.


2 Answers

try something like

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

and

var nextMonthLastDay = new moment().add(2, 'months').date(0)
like image 68
Lazy Coder Avatar answered Nov 24 '22 12:11

Lazy Coder


or more verbose:

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

nextMonthLastDay: moment().add(1, 'months').endOf('month')
like image 29
iulial Avatar answered Nov 24 '22 13:11

iulial