guttyguppy Posted January 20, 2010 Share Posted January 20, 2010 Hi, how can I set a variable to contain the number of days left until a future date? Quote Link to comment https://forums.phpfreaks.com/topic/189108-get-number-of-days-remaining-until-a-date/ Share on other sites More sharing options...
guttyguppy Posted January 20, 2010 Author Share Posted January 20, 2010 GG-here's how: $future = strtotime('4 July 2010'); $now = time(); $timeleft = $future-$now; $daysleft = round((($timeleft/24)/60)/60); Quote Link to comment https://forums.phpfreaks.com/topic/189108-get-number-of-days-remaining-until-a-date/#findComment-998388 Share on other sites More sharing options...
guttyguppy Posted January 20, 2010 Author Share Posted January 20, 2010 Thanks Me! Quote Link to comment https://forums.phpfreaks.com/topic/189108-get-number-of-days-remaining-until-a-date/#findComment-998389 Share on other sites More sharing options...
sudeeppgm Posted February 6, 2013 Share Posted February 6, 2013 <?php //Convert to date $datestr="2013-02-06 19:10:18";//Your date $date=strtotime($datestr);//Converted to a PHP date (a second count) //Calculate difference $diff=$date-time();//time returns current time in seconds $days=floor($diff/(60*60*24));//seconds/minute*minutes/hour*hours/day); $hours=round(($diff-$days*60*60*24)/(60*60)); //Report echo "$days days $hours hours remain<br />";echo "<br>"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/189108-get-number-of-days-remaining-until-a-date/#findComment-1410400 Share on other sites More sharing options...
Barand Posted February 6, 2013 Share Posted February 6, 2013 Don't resurrect old threads. But at least provide an up-to-date solution if you must. $futureDate = '2013-12-25'; $d = new DateTime($futureDate); echo $d->diff(new DateTime())->format('%a'); //--> 321 Quote Link to comment https://forums.phpfreaks.com/topic/189108-get-number-of-days-remaining-until-a-date/#findComment-1410405 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.