1 i f 2 <--- 해석가능하시죠 ?

Posted
Filed under dog발;/php
function cal_diff_date($date1, $date2)
{
	if(version_compare("5.3", phpversion(), "<="))
	{
		$date_1 = new DateTime($date1);
		$date_2 = new DateTime($date2);
		$date_diff = $date_1->diff($date_2);

		return array(
			"year" => $date_diff->y,
			"month" => $date_diff->m,
			"day" => $date_diff->d,
			"hour" => $date_diff->h,
			"minute" => $date_diff->i,
			"second" => $date_diff->s
		);
	}
	else
	{
		$date_1 = strtotime($date1);
		$date_2 = strtotime($date2);
		$sec = $date_1 - $date_2;
		$sec = intval(abs($sec));

		$ret = array(
			"year" => 0,
			"month" => 0,
			"day" => 0,
			"hour" => 0,
			"minute" => 0,
			"second" => 0
        );
		
		if(0 == $sec)
			return $ret;

		$units = array(
			"year" => 365*24*60*60,
			"month" => 30*24*60*60,
			"day" => 24*60*60,
			"hour" => 60*60,
			"minute" => 60,
			"second" => 1
		);

		foreach($units as $unit => $val)
		{
			$value = floor($sec / $val);
			$ret[$unit] = $value;
			$sec -= $value * $val;
		}

		return $ret;
	}
}

echo cal_diff_date(날짜1, 날짜2);
2016/07/07 10:23 2016/07/07 10:23