belongs to collection: PHP Basic Programs
In this code example we are taking two times and getting their differences, following code can be used to get exact time difference between two times.
<?php $time1 = "09:00"; $time2 = "17:00"; function get_time_difference($time1, $time2) { $time1 = strtotime($time1); $time2 = strtotime($time2); if ($time2 < $time1) { $time2 += 86400; } return date("H:i", strtotime("00:00") + ($time2 - $time1)); } $timediff = get_time_difference($time1, $time2); // 12:15:29 printf("Difference between in time : " . $timediff); print "</br>"; ?>
Output
Difference between in time : 08:00
total answers (1)
start bookmarking useful questions and collections and save it into your own study-lists, login now to start creating your own collections.
Source Code and Output to get time difference
Output
need an explanation for this answer? contact us directly to get an explanation for this answer