geneSummons
0
Q:

php time difference in hours

	date_default_timezone_set("Africa/Johannesburg");
    $now = new DateTime();
    $future_date = new DateTime('2020-10-21 00:00:00');
    
    $interval = $future_date->diff($now);
    
    echo ($interval->format("%a") * 24) + $interval->format("%h"). " hours". $interval->format(" %i minutes ");
    print_r($now->format('Y-m-d H:i:s'));
0
$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
}
0

New to Communities?

Join the community