📅 Get beginning and end of week with Moment.js
To get the date for beginning of week for a date in moment you can use the startOf
and endOf
functions on moment objects.
NOTE: Remember that the start of week will depend on the user's locale settings on their machine. If you want to use start of week based on ISO 8601 you can use moment().startOf('isoWeek');
The same technique can be used for start of month (startOf('month')
), start of year (startOf('year')
) and even quarter (startOf('quarter');
).