I need to work with some logic that requires week begins on Monday (not Sunday).
There is a function start of week I can use:
moment().tz('America/Los_Angeles').startOf('week').add(1, 'day')
However if its Sunday, I need to use last week's date and add 1 to get monday.
I'm hoping there is an easier to just get "last monday" no matter what the date is.
I found the answer (documented) but there is a isoWeek
which will start the week on Monday instead of Sunday.
Start week on Sunday:
moment().startOf('week');
Start week on Monday:
moment().startOf('isoWeek');
To find the last Monday just use
moment().isoWeekday(-6); // ISO day of the week with 1 being Monday and 7 being Sunday.
Or Locale Aware version
moment().weekday(-7); // when Monday is the first day of the week
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