Jump to content

working with time


maxim

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 ?
Link to comment
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]
Link to comment
Share on other sites

  • 2 weeks later...
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.