php between time code example
Example 1: php hour between
$currentTime = (new DateTime('01:00'))->modify('+1 day');
$startTime = new DateTime('22:00');
$endTime = (new DateTime('07:00'))->modify('+1 day');
if ($currentTime >= $startTime && $currentTime <= $endTime) {
// Do something
}
Example 2: calculate time difference php
$time1 = new DateTime('09:00:59');
$time2 = new DateTime('09:01:00');
$interval = $time1->diff($time2);
echo $interval->format('%s second(s)');
Result: 1 second(s)