Day Of Week function
Author Message
Day Of Week function

Although this may sound like some elementary project, I was wondering if anybody
knows/remembers a function to figure out the day of week given the month, date
and year.

Wed, 18 Jun 1902 08:00:00 GMT
Day Of Week function

Quote:

> Although this may sound like some elementary project, I was wondering if anybody
> knows/remembers a function to figure out the day of week given the month, date
> and year.

Based on a recent newsgroup posting, I wrote this function.  Not extensively tested
but I tried a few values and it seems to work.  The original poster described this
as Zeller's algorithm.

function zeller(day, month, year : integer) : integer;
{ Returns the day of the week, 0 = Sunday, 1 = Monday, ..., 6 = Saturday.
day   - day of the month, 1 to 31.
month - month of the year, 1 to 12.
year  - a four digit integer, ie 1996.  }

begin
month := month - 2;
if month <= 0 then
begin
month := month + 12;
year := year - 1;
end;
zeller := ( day + (13 * month - 1) div 5 + 5 * (year mod 100) div 4
- 7 * year div 400) mod 7;
end;  { of function zeller }

Good luck.
Bob.

Wed, 18 Jun 1902 08:00:00 GMT
Day Of Week function

:Although this may sound like some elementary project, I was wondering if anybody
:knows/remembers a function to figure out the day of week given the month, date
:and year.

Covered in

3) What is the code for the weekday of a given date?

tsfaqp.zip Common Turbo Pascal Questions and Timo's answers

All the best, Timo

....................................................................

Moderating at ftp:// & http://garbo.uwasa.fi archives  193.166.120.5
Department of Accounting and Business Finance  ; University of Vaasa

Wed, 18 Jun 1902 08:00:00 GMT

 Page 1 of 1 [ 3 post ]

Relevant Pages