datetime - How to calculate seconds in php -
i have code:
$hours = floor($differenceinhours); $minutes = ($differenceinhours-$hours)*60; $seconds = ':00'; $total=$hours . ":" . $minutes .':' . $seconds; echo $total;
i want know on how calculate seconds. formula?
you can use second parameter of date
function format number of seconds formatted time notation. number of hours larger 24, considers 1 day, you'll have take account treating hours separately.
echo floor($differenceinhours) . ':' . date('i:s', ($differenceinhours - floor($differenceinhours)) * 3600);
if not want treat hours separately, can use:
echo date('d h:i:s', $differenceinhours * 3600);
(of course, when reaches 31 days, considers month, et cetera...)
Comments
Post a Comment