Jens14 Posted March 16, 2007 Share Posted March 16, 2007 function date_diff($str_start, $str_end) { $str_start = strtotime($str_start); $str_end = strtotime($str_end); $nseconds = $str_end - $str_start; $ndays = round($nseconds / 86400); $nseconds = $nseconds % 86400; $nhours = round($nseconds / 3600); $nseconds = $nseconds % 3600; $nminutes = round($nseconds / 60); $nseconds = $nseconds % 60; if ($ndays != 0) { echo $ndays." days, ".$nhours." hours, ".$nminutes." minutes, ".$nseconds." seconds.<br>\n"; } if ($ndays = 0) { echo $nhours." hours, ".$nminutes." minutes, ".$nseconds." seconds.<br>\n"; } } date_diff("2007/03/14 13:15:45", "2007/03/16 14:00:00"); date_diff("2007/03/16 13:45:00", "2007/03/16 14:00:00"); This is the code of my function, what I need is that when days are 0, it only needs to show hours, minutes and seconds, when days and hours are 0 only minutes and seconds, when days, hours and minutes are 0 it only needs to show seconds, I've made a start but even that doesn't work. Can anyone help? Link to comment https://forums.phpfreaks.com/topic/42966-help-me-please/ Share on other sites More sharing options...
Jens14 Posted March 16, 2007 Author Share Posted March 16, 2007 I need this in an array by the way. Link to comment https://forums.phpfreaks.com/topic/42966-help-me-please/#findComment-208745 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.