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: <7260@star.cs.vu.nl> Date: 8 Aug 90 18:54:52 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 Another point, I forgot to mention in my previous followup, is that the number on which you do the % operation may be negative, and so may be the result. Using the result as an index to a table of day names then may cause a program crash. Instead, use W = ((...expression...) % 7 + 7) % 7 Bert IJff.