Path: utzoo!mnetor!tmsoft!torsqnt!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!uakari.primate.wisc.edu!aplcen!simpson From: simpson@aplcen.apl.jhu.edu (Simpson David Grant) Newsgroups: comp.lang.pascal Subject: Re: Name of day from date & year? Keywords: dayname date year day Message-ID: <1991Feb18.161533.21099@aplcen.apl.jhu.edu> Date: 18 Feb 91 16:15:33 GMT References: <1991Feb15.121713.10075@newcastle.ac.uk> Reply-To: simpson@aplcen (Simpson David Grant) Organization: Johns Hopkins University Lines: 29 In article <1991Feb15.121713.10075@newcastle.ac.uk> Boye.Tranum@newcastle.ac.uk (B. Tranum) writes: >I need to find out the name of the day (Monday, Tuesday etc.) from the date >and the year. For example, which day was 10-02-91. - It was a Sunday. > >Does anybody have a nice routine, in Pascal or in English, to do this. I would >be very pleased if you could help me. > There is an article in the latest issue of the Journal of Recreational Mathematics that has a routine for doing this. Given a month m, day d, and year y in the Gregorian calendar, the day of week D (where 0=Sunday, 1=Monday, ..., 6=Saturday) can be found from D = ((23*m/9)+d+4+y+(z/4)-(z/100)+(z/400)-2(if m>=3)) mod 7 where z = y-1 if m<3 z = y otherwise (See "The Ultimate Perpetual Calendar" by Keith & Craver, J. Rec. Math., v22 n4 p280). They include a (if you'll excuse this) C function: dayofweek (y,m,d) { return ((23*m/9+d+4+(m<3?y--:y-2)+y/4-y/100+y/400)%7); } David Simpson