Moment.js not including 31th day

by Massaget   Last Updated June 13, 2019 08:26 AM

I'm using moment.js library to get a date. When I set date to month's end it always returns 30th of each month. But it's not considering that some months has 31 day. How to fix it? Sorry for terrible english.

case 'currentMonth':
        this.dateTo = moment().endOf('month');
        this.dateFrom = moment().startOf('month');

for example: this.dateTo in the next month (july) will return 30.07.19, but there is 31 day in this month

Answers 1

The basic use of moment() will default to the current month. In order to get next month (July) you need to add a month to the date.

var date = moment().add('months', 1).endOf('month');
Peter Meadley
Peter Meadley
June 13, 2019 08:25 AM

Related Questions

Updated July 26, 2019 13:26 PM

Updated November 04, 2018 06:26 AM

Updated June 20, 2017 01:26 AM

Updated November 17, 2018 22:26 PM

Updated February 17, 2019 10:26 AM