Starting the Week on Monday With Isoweekday()

Starting the week on Monday with isoWeekday()

You just need to replace begin.startOf('isoWeek'); with begin.startOf('week');.

Moment.js set week start on Monday

Add this to your code

moment.updateLocale('en', {
week: {
dow : 1, // Monday is the first day of the week.
}
});

moment.updateLocale('en', {  week: {    dow : 1, // Monday is the first day of the week.  }});

var weeknumber = moment("2016-01-02", "YYYY-MM-DD").week();var weeknumber2 = moment("2016-01-03", "YYYY-MM-DD").week();console.log("02 is in week " + weeknumber);console.log("03 is in week " + weeknumber2);
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.18.1/moment.min.js"></script>

Using moment's isoWeekday to create a date grid

According to some pieces put together from https://momentjs.com/docs/#/customization/ and https://momentjs.com/docs/#/i18n/changing-locale/, you can use moment.updateLocale to override the locale configuration globally, like so:

moment.updateLocale('en', {    week: {        dow: 6  //week starts on saturday    }});

Determine first day of a week by a given date in moment js

The correct answer will be:

var begin = moment().subtract(1, 'week').startOf('week').format("YYYY MM DD");
var end = moment().subtract(1, 'week').endOf('week').format("YYYY MM DD");

Thanks to help by @MattJohnson

Change start of the week to Monday

OK, I got it.
Instead of trying to get explicit day as start of the week, startOf('isoWeek') should be used.
So instead of

date = this.state.month.clone().startOf("month").add("w" - 1).day(0),

I did:

date = this.state.month.clone().startOf("month").add("w"-1).startOf('isoWeek'),

and now it looks right:

Sample Image

How to get count of days when week starts from Monday till current date in Python

According to the documentation isoweekday should do the trick

import datetime
dt = datetime.datetime.now()
dt.isoweekday()

returns 4 on Thursday



Related Topics



Leave a reply



Submit