maxim Posted June 26, 2006 Share Posted June 26, 2006 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 More sharing options...
Barand Posted June 26, 2006 Share Posted June 26, 2006 [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 More sharing options...
maxim Posted June 26, 2006 Author Share Posted June 26, 2006 that wroked perfectly. mktime ehi 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 Link to comment https://forums.phpfreaks.com/topic/12957-working-with-time/#findComment-49833 Share on other sites More sharing options...
Barand Posted July 7, 2006 Share Posted July 7, 2006 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. Link to comment https://forums.phpfreaks.com/topic/12957-working-with-time/#findComment-54577 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.