Day Of Week

This algorithm finds the current day of week according to the input date.



									enum DayOfWeek
{
	Sunday,
	Monday,
	Tuesday,
	Wednesday,
	Thursday,
	Friday,
	Saturday
};

enum DayOfWeek GetDayOfWeek(unsigned int year, char month, char day) {
	char monthTable[] = { 0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4 };

	year -= (unsigned int)((month < 3) ? 1 : 0);

	return (enum DayOfWeek)((year + year / 4 - year / 100 + year / 400 + monthTable[month - 1] + day) % 7);
}
								


Example

									enum DayOfWeek value = GetDayOfWeek(2015, 8, 7);
								


Output

									Friday