Bootstrap 3 Datetimepicker 3.0.0 - make a week start on Monday
Asked Answered
L

9

16

There are few reasons I use Bootstrap 3 Datetimepicker 3.0.0 in my MVC 5 project.

Any idea how to offset week start so it starts from Monday? Language tag also not working.

 $(function () {
    $('#PickupTime').datetimepicker({
     weekStart: 1
    });
 });

This is not working because it is not the same bootstrap-datapicker.js

Logistician answered 25/6, 2014 at 13:55 Comment(0)
L
4

Instead of using moment.js I used moment-with-langs.js (I guess it came with default package ASP.NET MVC 5).

By calling:

<script type="text/javascript">
    $('#DateTime').datetimepicker({
        language: "hr"
    });
</script>

thing works, finally the calender starts from monday.

UPDATE: Even better, add key to web.config

<appSettings>    
    <add key="Culture" value="hr" />
</appSettings>

and then

$(document).ready(function () {
    $(document).on('focus', '#Date', function () {
        $(this).datetimepicker({
            locale: '@System.Configuration.ConfigurationManager.AppSettings["Culture"]',
            format: 'DD:MM:YYYY',
        });
    });
});
Logistician answered 28/6, 2014 at 23:25 Comment(0)
B
34

If you are using moment.js from v2.8.1 onwards, add the below code before calling datetimepicker().

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

$('#DateTime').datetimepicker();

If you are using old version of moment.js, do the following

moment.lang('en', {
  week: { dow: 1 }
});

$('#DateTime').datetimepicker();
Bibliolatry answered 18/7, 2015 at 15:0 Comment(1)
This works as expected. Shows Monday as the first day on the calendar. In addition to this i needed the Monday and Sunday from any date they picked. i.e if they choose 08/09/2018 (MM/DD/YYYY) then i needed 08/06/2018 and 08/12/2018 . to Get those I used the Weekday() function. i.e moment(new Date()).weekday(6).format("MM/DD/YYYY") which gave me Sunday for the week momentjs.com/docs/#/get-set/weekdayStablish
N
7

You can also override the dow value via the locale when calling datetimepicker()

$('#myid').datetimepicker({
    format:'YYYY-MM-DD',
    locale:  moment.locale('en', {
        week: { dow: 1 }
    }),
});
Norseman answered 18/1, 2018 at 23:43 Comment(1)
Worked like a sharm! ThanksTetrad
Q
4

According to the options for Datetimepicker this is not possible. It only supports the following properties:

$.fn.datetimepicker.defaults = {
    pickDate: true,                 //en/disables the date picker
    pickTime: true,                 //en/disables the time picker
    useMinutes: true,               //en/disables the minutes picker
    useSeconds: true,               //en/disables the seconds picker
    useCurrent: true,               //when true, picker will set the value to the current date/time     
    minuteStepping:1,               //set the minute stepping
    minDate:`1/1/1900`,               //set a minimum date
    maxDate: ,     //set a maximum date (defaults to today +100 years)
    showToday: true,                 //shows the today indicator
    language:'en',                  //sets language locale
    defaultDate:"",                 //sets a default date, accepts js dates, strings and moment objects
    disabledDates:[],               //an array of dates that cannot be selected
    enabledDates:[],                //an array of dates that can be selected
    icons = {
        time: 'glyphicon glyphicon-time',
        date: 'glyphicon glyphicon-calendar',
        up:   'glyphicon glyphicon-chevron-up',
        down: 'glyphicon glyphicon-chevron-down'
    }
    useStrict: false,               //use "strict" when validating dates  
    sideBySide: false,              //show the date and time picker side by side
    daysOfWeekDisabled:[]          //for example use daysOfWeekDisabled: [0,6] to disable weekends 
};

Source: http://eonasdan.github.io/bootstrap-datetimepicker/#options

You can disable the weekend if you don't want to see sunday.

Quadriga answered 25/6, 2014 at 14:0 Comment(5)
But still left column is sunday, and people expect mondayLogistician
In bootstrap-datapicker.js I have offseted the names, but only names get mooved, not the dates itself, so entire calender is not correct. Eaven treid changing in moment.js, but same thing.Logistician
Any replacement sugestions?Logistician
Finally i switched to github.com/smalot/bootstrap-datetimepicker but will follow development of first one.Logistician
NO i didn't. It is buggy and simply not working. Gong back to original.Logistician
L
4

Instead of using moment.js I used moment-with-langs.js (I guess it came with default package ASP.NET MVC 5).

By calling:

<script type="text/javascript">
    $('#DateTime').datetimepicker({
        language: "hr"
    });
</script>

thing works, finally the calender starts from monday.

UPDATE: Even better, add key to web.config

<appSettings>    
    <add key="Culture" value="hr" />
</appSettings>

and then

$(document).ready(function () {
    $(document).on('focus', '#Date', function () {
        $(this).datetimepicker({
            locale: '@System.Configuration.ConfigurationManager.AppSettings["Culture"]',
            format: 'DD:MM:YYYY',
        });
    });
});
Logistician answered 28/6, 2014 at 23:25 Comment(0)
T
4

I have just done! In moment.js change this line:

_week : {
    dow : 1, // Sunday is the first day of the week.
    doy : 6  // The week that contains Jan 1st is the first week of the year. 
},

'dow' MUST BE 1 and the week starts at Monday.

Trephine answered 27/11, 2014 at 12:37 Comment(0)
A
0

open jquery.datetimepicker.js and find variable "dayOfWeekStart" and set it to 1

Admonitory answered 10/10, 2014 at 17:7 Comment(3)
The OP was referring to Eonasdan Bootstrap-Datepicker. This has nothing to do with jQuery's datepicker.Dissemblance
Nothing to do with OP's question.Translator
not edit, but use as option $(".dataPicker").datetimepicker({ dayOfWeekStart: 1 });Dickenson
B
0
'locale' => [
    'firstDay' => 1
]
Bifid answered 26/1, 2015 at 16:52 Comment(0)
T
0

I stumbled upon the same question, and i'm using:

And, following the answer of user3928861 I found the answer on line 961 of moment.js as follows:

var defaultLocaleWeek = {
    dow : 1, // Sunday is the first day of the week.
    doy : 6  // The week that contains Jan 1st is the first week of the year.
};
Testament answered 4/8, 2015 at 21:7 Comment(0)
P
0

Datetimepicker has an option to set that to match wherever you are in the world (see the locale option http://eonasdan.github.io/bootstrap-datetimepicker/Options/#locale)

You can manually override it

$('#DateTime').datetimepicker({
    locale: moment.local('en')
});
Pilaf answered 21/3, 2016 at 17:55 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.