How to check if current time falls within a specific range on a week day using jquery/javascript?
This should hopefully help:
function checkTime() {
var d = new Date(); // current time
var hours = d.getHours();
var mins = d.getMinutes();
var day = d.getDay();
return day >= 1
&& day <= 5
&& hours >= 9
&& (hours < 17 || hours === 17 && mins <= 30);
}
Using the current time you could do something like this:
var now = new Date(),
day = now.getDay(),
hours = now.getHours();
//Check if day is Mon-Fri
if(0 < day < 6) {
//check between 9am and 5pm
if(9 <= hours <= 17) {
if(hours !== 17 || now.getMinutes() <= 30) {
//your jQuery code here
}
}
}
var now = new Date();
var dayOfWeek = now.getDay();
if(dayOfWeek > 0 && dayOfWeek < 6){
//falls on a weekday
if (now.getHours() > 9 && (now.getHours() < 17 && now.getMinutes() < 30)) {
//it's in schedule
}
}