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? 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); 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! 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>"; ?> 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 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
Archived
This topic is now archived and is closed to further replies.