Cristi B Cristi B - 1 year ago 102
PHP Question

Calculate remaining seconds in php

I have this code:

$d = ($subTime/(60*60*24))%365;
$h = ($subTime/(60*60))%24;
$m = ($subTime/60)%60;
$s = ($subTime);

echo $d." days\n";
echo $h." hours\n";
echo $m." minutes\n";
echo $s." seconds\n";

It echoes: 90 days 0 hours 32 minutes 7777955 seconds

Is there a formula that instead of 7777955 seconds to display from 1 to 60?

Answer Source

Just use modulo for this as well:

$s = $subtime % 60;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download