Return to Snippet

Revision: 22701
at January 19, 2010 16:38 by jkjeldgaard


Initial Code
function timeBetweenNowAndDeadline($deadline) {
	$currentDate = date("U");
	$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;
}

Initial URL

                                

Initial Description
modified version of:
http://www.linein.org/blog/2008/04/04/find-time-between-two-dates-in-php/

Initial Title
time between now and future date. (days, hours, minutes, seconds

Initial Tags
date

Initial Language
PHP