#native_company# #native_desc#
#native_cta#

Subtracts two dates

By Kevin Gryczan
on August 15, 2004

Version: 2.0

Type: Function

Category: Calendars/Dates

License: Other

Description: returns the difference between two date as an integer

function diffofdays($s_date,$e_date)
{
	if(strstr($s_date,"/")) {
		$s_exp = explode("/",$s_date);
		$e_exp = explode("/",$e_date);
		$s_ts = mktime(0,0,0,$s_exp[0],$s_exp[1],$s_exp[2]);
		$e_ts = mktime(0,0,0,$e_exp[0],$e_exp[1],$e_exp[2]);
		$s_day = date("z",$s_ts);
		$e_day = date("z",$e_ts);
		if ($s_day > $e_day)
		{
			if (date("L", $s_ts) == 1)
			{
				$diff = (366 - $s_day) + $e_day;
				echo $diff;
			}
			
			else
			{
				$diff = (365 - $s_day) + $e_day;
				echo $diff;
			}
			
		}
		
		else
		{
			$diff = $e_day - $s_day;
		}
	} elseif(strstr($s_date,"-")) {
		$s_exp = explode("-",$s_date);
		$e_exp = explode("-",$e_date);
		$s_ts = mktime(0,0,0,$s_exp[1],$s_exp[2],$s_exp[0]);
		$e_ts = mktime(0,0,0,$e_exp[1],$e_exp[2],$e_exp[0]);
		$s_day = date("z",$s_ts);
		$e_day = date("z",$e_ts);
		if ($s_day > $e_day)
		{
			if (date("L", $s_ts) == 1)
			{
				$diff = (366 - $s_day) + $e_day;
				echo $diff;
			}
			
			else
			{
				$diff = (365 - $s_day) + $e_day;
				echo $diff;
			}
			
		}
		
		else
		{
			$diff = $e_day - $s_day;
		}
	} else {
		echo "Unrecognized Date Format";
	}
	return($diff);
	unset($diff);
}