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

Popular posts from this blog

plot - Remove Objects from Legend When You Have Also Used Fit, Matlab -

java - Why does my date parsing return a weird date? -

Need help in packaging app using TideSDK on Windows -