Search code examples
phptimecountdownmktime

Count down to EST Hour everyday?


How would i count down to a specific hour every day, say 12PM EST time... So that it would countdown as 1 Hour 56 Minutes until 12PM / Lunch? I'm looking for something short and simple, no need for CSS or JS as it will be text and only update when the page is refreshed.


Solution

  • Here's what i was looking for in case it will help someone else.

    function countdown($year, $month, $day, $hour, $minute)
    {
    
    $the_countdown_date = mktime($hour, $minute, 0, $month, $day, $year, -1);
    $current = time();
    
    $difference = $the_countdown_date - $current;
    if ($difference < 0) $difference = 0;
    
    $days = floor($difference/60/60/24);
    $hours = floor(($difference - $days*60*60*24)/60/60);
    $minutes = floor(($difference - $days*60*60*24 - $hours*60*60)/60);
    
    echo "Checkback in ".$hours." hours and ".$minutes." minutes";
    }
    
    countdown(2016,1,1,12,0);