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?