PHP countdown with hours, minutes and seconds
Posted: Thu Sep 03, 2015 4:59 am
Trying to figure out how to create a UDT that displays hours, minutes and seconds (ex. 00:05:20).
I'm going after the script posted on here a few years ago. Been trying to modify it by adding seconds, but I'm not good enough to figure out what I'm doing wrong. Thankful for any help
I'm going after the script posted on here a few years ago. Been trying to modify it by adding seconds, but I'm not good enough to figure out what I'm doing wrong. Thankful for any help
Code: Select all
$year = $params['year'];
$month = $params['month'];
$day = $params['day'];
$hour = $params['hour'];
$minute = $params['minute'];
$countdown = "There are ";
$the_countdown_date = mktime($hour, $minute, 0, $month, $day, $year);
$today = time();
$difference = $the_countdown_date - $today;
if ($difference < 0) $difference = 0;
$days_left = floor($difference/60/60/24);
$hours_left = floor(($difference - $days_left*60*60*24)/60/60);
$minutes_left = floor(($difference - $days_left*60*60*24 - $hours_left*60*60)/60);
$countdown .= $days_left." days ";
$countdown .= $hours_left." hours and ";
$countdown .= $minutes_left." minutes left.";
echo $countdown;