Mario Ortegón Mario Ortegón - 5 days ago 5
PHP Question

Backward-counting day display in php

I am a complete newbie in PHP. 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.

How is this accomplished?

Answer
<?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.

Comments