Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
46
rated 0 times [  50] [ 4]  / answers: 1 / hits: 131822  / 7 Years ago, wed, february 15, 2017, 12:00:00

I use the following code to get startDate and endDate of the last months.



// Previous month
var startDateMonthMinusOne = moment().subtract(1, month).startOf(month).unix();
var endDateMonthMinusOne = moment().subtract(1, month).endOf(month).unix();

// Previous month - 1

var startDateMonthMinusOne = moment().subtract(2, month).startOf(month).unix();
var endDateMonthMinusOne = moment().subtract(2, month).endOf(month).unix();


How can i do to get also the month name ? (January, February, ...)


More From » momentjs

 Answers
3

Instead of unix() use the format() function to format the datetime using the MMMM format specifier for the month name.



var monthMinusOneName =  moment().subtract(1, month).startOf(month).format('MMMM');


See the chapter Display / Format in the documentation


[#58930] Monday, February 13, 2017, 7 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
andrea

Total Points: 445
Total Questions: 95
Total Answers: 103

Location: Tonga
Member since Tue, Nov 30, 2021
3 Years ago
;