php - How we can get difference of time In "H:i:s" time format as given scenario? -


here scenario have 2 time given have time part of datetime in 24 hour format

$start_time = "23:00:00"; $end_time = "07:00:00"; 

how can calculate duration hours , if start_time's hour part greater $end_time's hour.

i create if, if start time bigger have calculate 24h (base_time) minus start time first.

$start_time = "23:00:00"; $end_time = "07:00:00"; $base_time = "24:00:00";  if ($start_time>$end_time) {  $time = $base_time-$start_time+$end_time; } else {  $time = $start_time-$end_time; } 

or can have here, if have day format given.

the way on datetime, far know, possible date. add pseudo date infront... , use diff :

$start_time = "23:00:00"; $end_time = "07:00:00"; $st = new datetime("0000-00-00".$start_time); $et = new datetime("0000-00-01".$end_time);  $interval = $st->diff($et); $time = $interval->format('%h:%i:%s'); 

Comments

Popular posts from this blog

javascript - Clear button on addentry page doesn't work -

c# - Selenium Authentication Popup preventing driver close or quit -

tensorflow when input_data MNIST_data , zlib.error: Error -3 while decompressing: invalid block type -