http://stackoverflow.com/a/17145145/1561146 function check_time($t1, $t2, $tn) {
$t1 = +str_replace(":", "", $t1);
$t2 = +str_replace(":", "", $t2);
$tn = +str_replace(":", "", $tn);
if ($t2 >= $t1) {
return $t1 <= $tn && $tn < $t2;
} else {
return ! ($t2 <= $tn && $tn < $t1);
}
}
$tests = array(
array("16:00:00", "22:30:00", "15:00:00"),
array("16:00:00", "22:30:00", "16:00:00"),
array("16:00:00", "22:30:00", "22:29:59"),
array("16:00:00", "22:30:00", "22:30:00"),
array("16:00:00", "22:30:00", "23:59:59"),
array("22:30:00", "16:00:00", "22:29:59"),
array("22:30:00", "16:00:00", "22:30:00"),
array("22:30:00", "16:00:00", "15:59:59"),
array("22:30:00", "16:00:00", "16:00:00"),
array("22:30:00", "16:00:00", "17:00:00")
);
foreach($tests as $test) {
list($t1, $t2, $t0) = $test;
echo "$t1 - $t2 contains $t0: " . (check_time($t1, $t2, $t0) ? "yes" : "no") . "\n";
}