Get the name of the day of the week from jquery ui calendar

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

for example, when choosing 14-3-2012, he should return on 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?

    }
});
+2
source share
5 answers

Create an array with a list of days in it ...

var weekday=new Array(7);
weekday[0]="Sunday";
weekday[1]="Monday";
weekday[2]="Tuesday";
weekday[3]="Wednesday";
weekday[4]="Thursday";
weekday[5]="Friday";
weekday[6]="Saturday";

Then, in your onselect function, get the day number and use the above array to return the day of the week.

onSelect: function(dateText, inst) {
  var date = $(this).datepicker('getDate');
  var dayOfWeek = weekday[date.getUTCDay()];
  // dayOfWeek is then a string containing the day of the week

}
+2
source

There are various formats from which you can display dates.

Check this box for all calendar compatible date formats.

In your case dateFormat: 'DD', WeekDays is displayed.

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

Just change the date format if you have no problems with the format. and then apply some magazine to get a weekday.

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

+2
source

Try:


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

}

+1
source

Use this code ....

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

Source: https://habr.com/ru/post/1584831/


All Articles