'Get week day name from jquery ui calendar

I want to get the name of the Day when choosing date from jquery ui calender.

for example, when choosing 14-3-2012 it should returns Wednesday.

$("input[name=date]").datepicker({
    dateFormat: 'yy-mm-dd',
    changeYear:true,
    changeMonth:true,
    onSelect: function(dateText, inst) {
         var date = $(this).datepicker('getDate');

         //what should I write here to get the day name?

    }
});


Solution 1:[1]

Just Change the Format of date if you don't have problem with format. and than apply some log to get weekday.

check this demo : http://jsfiddle.net/cnvwu/

Solution 2:[2]

There are various formats from which you can display the dates.

Check this for all the date formats compatible with the calendar.

In your case dateFormat: 'DD' displays the WeekDays.

$("input[name=date]").datepicker({
    dateFormat: 'DD',
    changeYear:true,
    changeMonth:true,
    onSelect: function(dateText, inst) {
         alert(dateText); // alerts the day name
    }
});

Solution 3:[3]

Try:


onSelect: function(dateText, inst) {
  var date = $(this).datepicker('getDate');
  var dayOfWeek = date.getUTCDay();

}

Solution 4:[4]

Use this code....

function(event, ui) {
    var date = $(this).datepicker('getDate');
    var dayOfWeek = date.getUTCDay();
};

Solution 5:[5]

I've run into this task now and in order to get the correct day name for users who are in GMT+... timezones, we need to use the getDay() function, not the getUTCDay() function.

onSelect: function() {
  var weekdays = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];  
  var date = $(this).datepicker('getDate');
  var dayOfWeek = weekdays[date.getDay()];
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Paresh Balar
Solution 2
Solution 3 Sudhir Bastakoti
Solution 4
Solution 5 Bandi