I am trying to show a specific div depending on the day and time.
So if the Day is between Monday - Friday and the Time is between 9am - 5:30pm,
then it will show div = class.open
if before or after that time, it will show div = class.closed
I have the following code that works to show the .open div when open, Monday-Friday 9am to 5pm. And it will show the .closed div from 0am to 9am. But I need it to show the closed div anytime it is outside of Monday-Friday 9am-5pm.
So I have 2 questions:
How do I have the .closed div show whenever it is not Monday-Friday 9am to 5pm?
How can I add minutes in, like open 8:30am to 5:30pm?
CODE
<div class="hours">We are OPEN</div>
<div class="closed">We are CLOSED</div>
$(document).ready(function () {
var d = new Date();
var dayOfWeek = d.getDay();
var hour = d.getHours();
// open hours Monday - Friday 9am - 5:pm = open
if (dayOfWeek === 6 || dayOfWeek === 0 || hour <= 9 || hour >= 17) {
$('.hours').hide();
}
// closed any other time than above * working from 0am -9am but none other
if (dayOfWeek === 6 || dayOfWeek === 0 || hour <= 0 || hour >= 9) {
$('.closed').hide();
}
});
Here is the example: JSFiddle