Reputation: 6812
I'm trying to get the last day of the month as an integer. So for the month december 31 should be returned.
moment().endOf('month').day()
This will, however, return 1 - even though
moment().endOf('month').format('YYYY-MM-DD')
returns the correct date. Can someone explain why and how to get the actual day?
Upvotes: 0
Views: 1302
Reputation: 202
var lastDate = moment().endOf('month').format('DD')
which returns the day and you can parseInt this for making it as integer
Upvotes: 0
Reputation: 1358
moment().endOf('month').format('DD')
also
moment().endOf('month').date();
Upvotes: 1
Reputation: 5290
day()
returns the day of the week, not the date
You want to use date()
instead
Upvotes: 1
Reputation: 2591
As galchen said, day() returns the day of the week. To get the date, manipulate the string:
var lastDay = moment().endOf('month').format('YYYY-MM-DD').split('-')[2];
Upvotes: -1
Reputation: 3434
To get the day of the month, you have to use .date()
instead. See the relevant part of the docs: http://momentjs.com/docs/#/get-set/date/
Upvotes: 5