Search code examples
javascriptjqueryjquery-uidatepickerjquery-ui-datepicker

jQuery: datepicker, alert the dayname of the selected


How can i alert the selected days name? Example 'Monday'.

So when you pick 7th june 2011 it will alert "Tuesday"

<script>
$(function() {
    $( "#date" ).datepicker({ 
     dateFormat: 'dd/mm/yy',
     onSelect: function(dateText, inst) {
    // how can i grab the day name of the day, example "Monday" and alert it out?
    // alert( ? );
     }
    });
});
</script>

Solution

  • The jQueryUI's Datepicker comes with a formatDate function that can do that for you. If you're using a localized version, it'll show the days in that language too.

    onSelect: function(dateText, inst) {
      var date = $(this).datepicker('getDate');
      alert($.datepicker.formatDate('DD', date));
    }
    

    For more information on localization of on Dapicker's utility functions, have a look at http://jqueryui.com/demos/datepicker/.