Days In Month

This algorithm finds the total days in a month according to the input date.



									public static byte DaysInMonth(uint year, byte month)
{
	byte daysInMonth;

	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;
}

private static bool IsLeapYear(uint year)
{
	return (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
}
								


Example

									byte value = DaysInMonth(2015, 8);
								


Output

									31