Tomislav Brtan
Tomislav Brtan

Reputation: 63

Show DIV during specific times of the day (eg., during store "open hours")

I need to toggle DIV visibility based on time so my site shows when my physical store is open.

For example:
- 07:00-15:59 = Show div
- 16:00-06:59 = Hide div

Thanks!

Upvotes: 6

Views: 8350

Answers (4)

sujivasagam
sujivasagam

Reputation: 1769

You can compare the current time with the time in which you need to show a specific div using jquery as follows:

$('#mydiv').hide();
$('#myclosediv').hide();

if(today.getHours() >= 7 && today.getHours() < 16){
 $('#myopendiv').show();
}   
else{
 $('#myclosediv').show();
}

If the current time is 7 AM to 4 PM, then the div with id 'myopendiv' will be shown. Else the other div.

Upvotes: 1

Identity1
Identity1

Reputation: 1155

You can use the following to get system time:

    var date = new Date();

    var time = date.getHours() + ":" + date.getMinutes() + ":" + date.getSeconds();
    $('div').hide()
    if(date.getHours()>7&&date.getHours()<16){
      $('div').show()
    }
    else 
    if(date.getHours()>=16&&date.getHours()<7){
      $('div').hide()
    }

Upvotes: 1

Pushkar Newaskar
Pushkar Newaskar

Reputation: 169

Here is a basic example.

//gets the current time. 
var d = new Date();
if(d.getHours() >= 7 && d.getHours() <= 15 ){
    $(".open").show();
    $(".closed").hide();
}
else {  
     $(".closed").show();
    $(".open").hide();
}

https://jsfiddle.net/16mnrL3b/

Upvotes: 5

Devsome
Devsome

Reputation: 89

You can try this

if ( date('H:i') >= "07:00" && date('H:i') <= "16:00" ) {
   echo 'Time between 7 and 16';
}else{
   echo 'Time is runned out';
}

Upvotes: 1

Related Questions