I've found plenty of solutions that output a bool if the day is before or after a specific date, but I can't seem to find one about time specifically in PHP.
I've got a script that I want to be available for use between 7:45AM and 3:45PM and only monday through friday - but never before or after these times or on weekends.
I've been racking my brain on how to do this, and I'm posting here because I'm sure there is a very simple way to do this that I am overlooking.
This is what I have so far:
$timeOfDay = date("h:iA");
$dayOfDay = date("D");
if(strcmp($dayOfDay,'Mon') != 0
||strcmp($dayOfDay,'Tue') != 0
||strcmp($dayOfDay,'Wed') != 0
||strcmp($dayOfDay,'Thu') != 0
||strcmp($dayOfDay,'Fri') != 0) {
//disable site
} else {
//if $timeOfDay is before 7:30AM or after 3:45PM, disable site ELSE enable site
}
To be clear, the script should only be online Monday-Friday between 7:45AM and 3:45PM.
EDIT: Another note - I am ONLY seeking the PHP logic in which I can get a true or false for, I can handle the rest of the code disabling the script etc.
$now = strtotime("now"); // here come current timestamp
$dt_start = strtotime(date("d.m.Y 07:45")); // timestamp of today 07:45
$dt_end = strtotime(date("d.m.Y 15:45")); // timestamp of today 15:45
$cur_day = date("w", $now); // number of cur day 0 to 6
if ((0 < $cur_day && $cur_day < 6) // check what day is it
&& ($dt_start < $now && $now < $dt_end)) { // check time interval
// do stuff
}