WayBehind WayBehind - 1 month ago 12
jQuery Question

Display Day of the Week after Date with bootstrap-datepicker

I'm using bootstrap-datepicker and would like to also display the actual day of the week in the text field right after the date.

Example:

12/01/2014 Monday


my datepicker configuration

$(document).ready(function () {

$('#calendar').datepicker({
format: "mm/dd/yyyy",
weekStart: 1,
autoclose: true,
todayHighlight: true,
});
});


The actual datepicker source is here:

https://bootstrap-datepicker.readthedocs.org/

Answer

You can try something like this, only add this part to your code:

$('#calendar').change(function () { //Your date picker input
    var eventDate = $('#calendar').val();
    var dateElement = eventDate.split("/");
    var dateFormat = dateElement[2]+'-'+dateElement[0]+'-'+dateElement[1];
    var date = new Date(dateFormat+'T10:00:00Z'); //To avoid timezone issues
    var weekday = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
    var day = weekday[date.getDay()];
    $('#calendar').val($('#calendar').val() + ' ' + day);
}); 

Hope works for you.

Comments