Is there a way that I get the last monday in the month with moment.js?
I know I can get the end of the month with:
moment().endOf('month')
But how about the last monday?
We can use the startOf method to get the first day of the current month. And we can use the endOf method to get the last day of the current month.
I've used it this way : new Date(moment(). subtract(1, 'weeks').
The moment(). month() method is used to get or set the month of the Moment object.
You're almost there. You just need to add a simple loop to step backward day-by-day until you find a Monday:
result = moment().endOf('month');
while (result.day() !== 1) {
result.subtract(1, 'day');
}
return result;
you get always monday with isoweek:
moment().endOf('month').startOf('isoWeek')
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