Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!ucbvax!ucsd!sdcsvax!ucsdhub!hp-sdd!hplabs!hpda!hpcuhb!hp-ses!hpcc01!azarian From: azarian@hpcc01.HP.COM (Randy Azarian) Newsgroups: comp.lang.pascal Subject: Re: Day-of-week algorithm, please! Message-ID: <1780001@hpcc01.HP.COM> Date: 9 Apr 89 19:55:08 GMT References: <19040@adm.BRL.MIL> Organization: HP Corporate Computing Center Lines: 33 FUNCTION calcnumdays (month,day,year : integer) : word; (* this function calculates the total number of days elapsed between parameters passed , month, day, and year, and january 1, 1901. this function is used to the day of the week, by knowing that january 1, 1901 was a tuesday. modulus division can then determine the day of the week by calculating something to the effect as follows: IF THE TOTAL NUMBER OF DAYS MODULUS 7 EQQUALS 0 THEN IT IS A TUESDAY. the rest of the days of the week can be calculated relative to the above statement. *) (* daysinmonth is a function you can write yourself that returns, obviously, the number of days in the month. i.e x := daysinmonth(2,88); x is set to 29 if the month is not february, then year can be anything *) var monthctr, total : integer; begin total := day -1; for monthctr := 1 to month-1 do total := total + daysinmonth(monthctr,year); total := total + 365 * (year - 1); total := total + + (year - 1) div 4; calcnumdays := total; end;