Mario Ortegón Mario Ortegón - 1 year ago 74
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

. 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 Source

    $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.