user1320260
user1320260

Reputation:

Check if current time is between 5pm on friday and 9am on monday

I am trying to get a section of a page to only appear after 5pm on a friday and shut off at 9am on a monday, every week. I know how to do this if i know the dates, but not sure how to do this otherwise.

At the moment I'm having to manually update my variables every week.

    $startDate = strtotime("08/02/2013 05:00PM"); 
    $endDate = strtotime("08/05/2013 09:00AM");

    if (time() > $startDate && time() < $endDate)    
    {
        // contents to display
    } 

Upvotes: 3

Views: 4314

Answers (2)

Michael Kunst
Michael Kunst

Reputation: 2988

Check if its friday after 5PM, saturday or sunday or monday before 9AM.

if((date('N') == 5 && date('G') >= 17) || in_array(date('N'), array(6,7)) || (date('N') == 1 && date('G') < 9))

date('N') gives you the weekday (From 1 for monday to 7 for sunday), and date('G') Gives you the hour of the day.

Upvotes: 12

Prabhukiran
Prabhukiran

Reputation: 149

check for the day using

$day = date('D');
$time = date('H');
$daysArray = array('Sat', 'Sun');
 if(($day == 'Fri' && $time >= '17') || in_array($day, $daysArray) || ($day == 'Mon' && $time <= '09'))
 {
   // Code to display page
 }

Upvotes: 2

Related Questions