Reputation: 148
I got some trouble making an awesome feature for my datepicker. The things i want to do is:
I want to disable the next 3 days if the current day is friday, and if its past 11AM.
$('#datetimepicker').datepicker({
format:'d/m/Y',
formatDate:'Y/m/d',
dayNamesMin: ['Søn', 'Man', 'Tir', 'Ons', 'Tor', 'Fre', 'Lør'],
monthNames: [ "Januar", "Februar", "Marts", "April", "Maj", "Juni", "Juli", "August", "September", "Oktober", "November", "December" ],
monthNamesShort: [ "Jan", "Feb", "Mar", "Apr", "Maj", "Jun", "Jul", "Aug", "Sep", "Okt", "Nov", "Dec" ],
minDate: +1,
beforeShow : function(){
var dateTime = new Date();
var hour = dateTime.getHours();
if(hour >= 11){
$(this).datepicker( "option", "minDate", "+2" );
}
}
});
I have been look around other examples on stackoverflow but nothing worked. So nows my time to try my luck!
Many thanks beforehand!
Upvotes: 0
Views: 787
Reputation: 6486
Your current javascript function doesn't take the day of the week into account. Just add some logic to also check that the current day is a Friday.
...
beforeShow : function(){
var dateTime = new Date();
var hour = dateTime.getHours();
var dayOfWeek = dateTime.getDay(); //check the day of the week
if(dayOfWeek == 5 && hour >= 11) {
$(this).datepicker( "option", "minDate", "+2" );
}
}
Note that the getDay()
function returns the day of the week as an 0-indexed integer, with Sunday being 0, and Saturday being 6. So date.getDay() == 5
is a Friday.
Upvotes: 1