Backward-counting day display in php
Question
I would like to show the number of days missing for a specific date. In other words, I want to display something like:
X days to go for the great event
using PHP and the server time.
Solution
<?php
$event_date = '2010-01-01 00:00:00';
$event_time = strtotime($event_date);
$diff = $event_time - time();
echo floor($diff/(24*60*60)).' days to go for the great event';
?>
Note: I'm totally side stepping any timezone considerations, so, be sure you read up on timezone issues associated with using the PHP datetime
functions.
OTHER TIPS
jakemcgraw's answer would have my vote, had I 15 rep. :)
You might want to use mktime() instead of strtotime(), though.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow