#### Archived

This topic is now archived and is closed to further replies.

# working with time

## Recommended Posts

Hi i would like to display a dynamic "countdown" on screen.

basicly i get the current timestamp. and have a set future time stamp.If i subtract the current time stamp from the future one am i right in believeing that i have the number of seconds left untill that future time is reached ?

if so i am totaly confuesed as to how to perfom maths on it. for example i want to display the weeks,days,hours and mins left untill the future date.

i can get the weeks by doing somethink like the following

[code]\$timeleft_timestamp = \$future_timestamp - \$current_timestamp;

\$weeks = \$timeleft_timestamp / 60 / 60 / 24 / 7;[/code]

is this correct. if so how do i go about getting the days,hours,mins.

im left with a number with alot of decimal places should i just use the round() function. will this be accurate ?

##### Share on other sites
[code]
\$timeleft = mktime(0,0,0,12,25,2006) - time();
\$weeks = floor(\$timeleft / (60 * 60 * 24 * 7));
\$timeleft %= (60 * 60 * 24 * 7);
\$days = floor(\$timeleft/ (60 * 60 * 24));
\$timeleft %= (60 * 60 * 24);
\$hrs = floor(\$timeleft/ (60 * 60));
\$timeleft %= (60 * 60);
\$mins = floor(\$timeleft/60);
\$secs = \$timeleft % 60;

echo "\$weeks weeks \$days days \$hrs hours \$mins mins \$secs secs";[/code]

##### Share on other sites
that wroked perfectly. mktime eh

i am pretty dissapointed tho. i would have like to be pointed in the right direction insed of being told the answer.

but thanks again anyway

##### Share on other sites
My apologies, there are a lot of people who need to be spoonfed with the answer and those who just need a hint. There is no way of knowing whiich. I'll try not to make the same mistake by helping you again.