/ Published in: PHP
modified version of:
http://www.linein.org/blog/2008/04/04/find-time-between-two-dates-in-php/
http://www.linein.org/blog/2008/04/04/find-time-between-two-dates-in-php/
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
function timeBetweenNowAndDeadline($deadline) { $diff = $deadline-$currentDate; $seconds = 0; $hours = 0; $minutes = 0; if($diff % 86400 <= 0){$days = $diff / 86400;} // 86,400 seconds in a day if($diff % 86400 > 0) { $rest = ($diff % 86400); $days = ($diff - $rest) / 86400; if($rest % 3600 > 0) { $rest1 = ($rest % 3600); $hours = ($rest - $rest1) / 3600; if($rest1 % 60 > 0) { $rest2 = ($rest1 % 60); $minutes = ($rest1 - $rest2) / 60; $seconds = $rest2; } else{$minutes = $rest1 / 60;} } else{$hours = $rest / 3600;} } if($days > 0){$days = $days.'d, ';} else{$days = false;} if($hours > 0){$hours = $hours.'h, ';} else{$hours = false;} if($minutes > 0){$minutes = $minutes.'m, ';} else{$minutes = false;} $seconds = $seconds.'s'; // always be at least one second return $days.''.$hours.''.$minutes.''.$seconds; }