Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!rutgers!mcnc!uvaarpa!vger!g_harrison From: g_harrison@vger.nsu.edu Newsgroups: comp.lang.pascal Subject: Re: Algorithm needed Message-ID: <46.27140d61@vger.nsu.edu> Date: 11 Oct 90 10:12:48 GMT References: <3334@vela.acs.oakland.edu> <1990Oct10.175221.17285@uwasa.fi> Lines: 58 In article <1990Oct10.175221.17285@uwasa.fi>, ts@uwasa.fi (Timo Salmi) writes: > In article <3334@vela.acs.oakland.edu> moconnor@argo.acs.oakland.edu writes: >>Could someone please mail me code such that given a date (something >>like, say, October 10th, 1990), it tells me the day of the week? ........ > A1: There is a wkdayfn function in /pc/ts/tspas22.arc Turbo Pascal > units collection to give the modern weekday based on Zeller's > congruence. Also you can find a more extensive Julian and Gregorian > weekday algorithm in Dr.Dobbs Journal, June 1989, p. 148. Furthermore > Press & Flannery & al, Numerical Recipes, has the weekday code. > > A2: Some will recommend the following kludge. Store the current > .....etc...... > > The wares (/pc/ts/tspas22.arc) are available by anonymous ftp from > chyde.uwasa.fi, Vaasa, Finland, 128.214.12.3, or by using our mail > .....etc...... > Prof. Timo Salmi (Moderating at anon. ftp site 128.214.12.3) > School of Business Studies, University of Vaasa, SF-65101, Finland > Internet: ts@chyde.uwasa.fi Funet: gado::salmi Bitnet: salmi@finfun I sent the following Pascal function to the original poster. It's very nice and VERY fast. I found it in "Computer Language Magazine" a few years ago: .................................................................... MONTHTYPE = 1..12; {January..December} DAYTYPE = 1..7; {Sunday..Saturday} {returns the first day of the MONTH in YEAR} function FIRST_DAY(MONTH : MONTHTYPE; YEAR : INTEGER) : DAYTYPE; var DAY, MON, YEA : INTEGER; begin YEA := YEAR; MON := MONTH; if MON <= 2 then begin MON := MON + 12; YEA := YEA - 1 end; DAY := (3 + (2*MON) + (((MON + 1)*6) div 10) + YEA + (YEA div 4) - (YEA div 100) + (YEA div 400)) mod 7; if DAY = 0 then FIRST_DAY := 7 else FIRST_DAY := DAY end; -------------------------------------------------------------------------- -- George C. Harrison INTERNET: g_harrison@vger.nsu.EDU -- -- Professor of Computer Science Subliminal Address: adA -- -- Norfolk State University -- -- The views expressed here are not necessarily those of -- -- the Univesity, my wife, or my children. -- --------------------------------------------------------------------------