I'm trying to get the difference in time between two given times e.g. first time '17:00:01' and then second time '17:47:25' and here's what I tried so far,
$start_time = "17:00:01";
$end_time = "17:47:25";
String in php is not object, so can't call
diff method on it.
diff method, you must change the string to
If you want to compare time difference in same day, you could try:
$start_time = "17:00:01"; $end_time = "17:47:25"; $start_datetime = new DateTime(date('Y-m-d').' '.$start_time); $end_datetime = new DateTime(date('Y-m-d').' '.$end_time); var_dump($start_datetime->diff($end_datetime));