Calculate number of days remaining

BobbaFett picture BobbaFett · Sep 23, 2011 · Viewed 27.8k times · Source

I would like to calculate the number of days remaining before a date. In my database I have a timestamp corresponding to the end date. For example Friday 30. I would like to say something like that :

7 days remaining... 6, 5, 4, etc

Can you help me please ?

Answer

Mob picture Mob · Sep 23, 2011
$future = strtotime('21 July 2012'); //Future date.
$timefromdb = //source time
$timeleft = $future-$timefromdb;
$daysleft = round((($timeleft/24)/60)/60); 
echo $daysleft;