Jump to content

time operation


bluetoother

Recommended Posts

you could try something like

$time1 = strtotime("18:02");$time2 = strtotime("17:55");$time3 = $time1 - $time2;$time4 = date('i:s', $time3);

Link to comment
Share on other sites

One other thing, if you try using

$time4 = date('h:i:s', $time3);

for some reason it says there are 4 hours in there somewhere, so here is alternate code I just wrote that works a little better.

$time1 = strtotime('18:02:00');$time2 = strtotime('17:55:00');$seconds = $time1 - $time2;$minutes = 0;$hours = 0;while ($seconds >= 60){	$seconds = $seconds - 60;	$minutes = $minutes + 1;}while ($minutes >= 60){	$minutes = $minutes - 60;	$hours = $hours + 1;}if ($seconds < 10){	$seconds = "0$seconds"; //if only one digit, give it the format "ss"}if ($minutes < 10){	$minutes = "0$minutes"; //if only one digit, give it the format "mm"}if ($hours < 10){	$hours = "0$hours"; //if only one digit, give it the format "hh"}echo "$hours:$minutes:$seconds"; //will now display in "hh:mm:ss" format

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...