# working with time

3 replies to this topic

### #1 maxim

maxim
• Members
• 48 posts

Posted 26 June 2006 - 08:09 PM

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

```\$timeleft_timestamp = \$future_timestamp - \$current_timestamp;

\$weeks = \$timeleft_timestamp / 60 / 60 / 24 / 7;```

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 ?

### #2 Barand

Barand
• Moderators
• Sen . ( ile || sei )
• 18,021 posts

Posted 26 June 2006 - 08:33 PM

```\$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";```

If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

 |baaGrid| easy data tables - and more|baaChart| easy line, column and pie charts

### #3 maxim

maxim
• Members
• 48 posts

Posted 26 June 2006 - 10:20 PM

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

### #4 Barand

Barand
• Moderators
• Sen . ( ile || sei )
• 18,021 posts

Posted 07 July 2006 - 10:34 PM

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.
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.