Reputation: 9858
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?
}
});
Upvotes: 3
Views: 22278
Reputation: 41
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()];
}
Upvotes: 1
Reputation: 78981
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
}
});
Upvotes: 2
Reputation: 338
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/
Upvotes: 2
Reputation: 38147
Create an array with the 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
}
Upvotes: 4
Reputation:
Use this code....
function(event, ui) {
var date = $(this).datepicker('getDate');
var dayOfWeek = date.getUTCDay();
};
Upvotes: 0
Reputation: 100175
Try:
onSelect: function(dateText, inst) {
var date = $(this).datepicker('getDate');
var dayOfWeek = date.getUTCDay();
}
Upvotes: 1