Jump to content

[SOLVED] a condition for between two times


jeff5656

Recommended Posts

$now = time();
$min = mktime('8');
$max = mktime('11','59');

if (($now >= $min) && ($now =< $max))
{
//Current time is between 8:00AM and 11:59AM
}

else
{
//Current time is NOT between 8:00AM and 11:59AM
}

 

Give this a shot. Keep in mind, I should have been asleep six hours ago, and I didn't bother to test.

This is an alternative where you can use the 'natural' date formats when defining the limits:

 

$timeCurr = time();
$timeStart = strtotime('8:00 am');
$timeEnd = strtotime('11:59 am');

if ($timeCurr > $timeStart && $timeCurr < $timeEnd) {
//doStuff
echo 'blah';
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.