Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uunet!mcsun!hp4nl!star.cs.vu.nl!engbert From: engbert@cs.vu.nl (Engbert Gerrit IJff) Newsgroups: comp.lang.c Subject: Re: Date functionality Message-ID: <7259@star.cs.vu.nl> Date: 8 Aug 90 18:46:01 GMT References: <171@ittc.wec.com> <357@taumet.com> Sender: news@cs.vu.nl Reply-To: engbert@cs.vu.nl (Engbert Gerrit IJff) Organization: VU Dept. of Computer Science, Amsterdam, The Netherlands Lines: 31 In article <357@taumet.com>, steve@taumet.com (Stephen Clamage) writes: ) fpb@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@taumet.com That works fine, but beware: if you take Jan and Feb as month 11 and 12 of the previous year, you have to take Y the previous year as well, and C the previous century, if necessary. At least that is what I found, when implementing the algorithm. Good luck. Bert.