Date functionality

Stephen Clamage steve at taumet.com
Sun Jul 29 07:54:18 AEST 1990


fpb at ittc.wec.com (Frank P. Bresz) writes:

>	I am looking for an algorithm to give me the day of the week when
>handed the current date.  I can't use any builtin routines from any OS
>(this is targeted for a real brain-damaged machine).

Here is an algorithm known as Zeller's congruence.

The day of the week (0 = Sunday) is given by
  W = ((26*M - 2) / 10 + D + Y + Y/4 + C/4 - 2*C) % 7
  where
	C is the century
	Y is the last two digits of the year
	D is the day of the month
	M is a special month number, where Jan and Feb are taken as
	  month 11 and 12 of the previous year
  and each division is truncating division, and cannot be combined.
-- 

Steve Clamage, TauMetric Corp, steve at taumet.com



More information about the Comp.lang.c mailing list