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
https://forums.phpfreaks.com/topic/12957-working-with-time/
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
https://forums.phpfreaks.com/topic/12957-working-with-time/#findComment-49799
Share on other sites

  • 2 weeks later...

Archived

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

×
×
  • 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.