Have an account? Sign in
Login  Register  Facebook
This Page is Under Construction! - If You Want To Help Please Send your CV - Advanced Web Core (BETA)
[Edit] Time Between Two Dates in PHP

Usage Example

$one_date = date("U");
$two_date = date("U", mktime(0,0,0,4,1,2008));
echo timeBetween($one_date, $two_date).'';
// displays "x days, x hours, x minutes, x seconds"
	function timeBetween($start_date,$end_date)
	{
		$diff = $end_date-$start_date;
 		$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.' days, ';}
		else{$days = false;}
		if($hours > 0){$hours = $hours.' hours, ';}
		else{$hours = false;}
		if($minutes > 0){$minutes = $minutes.' minutes, ';}
		else{$minutes = false;}
		$seconds = $seconds.' seconds'; // always be at least one second

		return $days.''.$hours.''.$minutes.''.$seconds;
	}