Days In Month
This algorithm finds the total days in a month according to the input date.
function IsLeapYear($year) {
return ($year % 4 == 0 && ($year % 100 != 0 || $year % 400 == 0));
}
function GetDaysInMonth($year, $month) {
$daysInMonth = 0;
if ($month == 4 || $month == 6 || $month == 9 || $month == 11)
{
$daysInMonth = 30;
}
else if ($month == 2)
{
if (IsLeapYear($year))
{
$daysInMonth = 29;
}
else
{
$daysInMonth = 28;
}
}
else
{
$daysInMonth = 31;
}
return $daysInMonth;
}
Example
$value = GetDaysInMonth(2016, 2);
Output
29