Cristi B Cristi B - 3 months ago 11
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

Just use modulo for this as well:

$s = $subtime % 60;
Comments