Day Of Year

This algorithm finds the number of current day in a year according to the input date.



									function IsLeapYear($year) {
	return ($year % 4 == 0 && ($year % 100 != 0 || $year % 400 == 0));
}

function GetDayOfYear($year, $month, $day) {
	$days = array(0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334);

	if (IsLeapYear($year) && $month >= 2)
		return $days[$month - 1] + $day + 1;

	return $days[$month - 1] + $day;
}
								


Example

									$value = GetDayOfYear(2015, 8, 7);
								


Output

									219