home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!zaphod.mps.ohio-state.edu!news.acns.nwu.edu!nucsrl!ddsw1!infopls!rhps!warlok
- From: warlok@rhps.chi.il.us (Jon L Fincher)
- Newsgroups: comp.lang.pascal
- Subject: Re: Day of week on a given date
- Message-ID: <w7BkuB4w165w@rhps.chi.il.us>
- Date: Fri, 20 Nov 92 18:21:43 CST
- References: <1992Nov17.042319.29002@cs.unca.edu>
- Organization: CrissySoft Incorporated
- Lines: 33
-
- snodgras@cs.unca.edu (Ryan Snodgrass) writes:
-
- > Does anyone know how to get the day of week given a specified date,
- > for example if the function were passed the date "11-16-92" then it would
- > return some number representing Monday? (I assume 1)
- >
- > If you could give me an example, or of where to look to get an example I
- > would really appreciate it.
- >
- > Ryan
- > snodgrass@uncavx.unca.edu
-
- Try using Zeller's Convergence formula. Works every time.
-
- The formula is:
-
- day = (2*m + int((3*(m+1))/5) + d + y + int (y/4) + lya ) mod 7
- lya = int (y/400) - int(y/100) + 1;
-
- where m=month number, 1-14 (13= last Jan, 14=last Feb)
- y=year, complete with century (1992, for example)
- d=day, which is the calendar day number (12th, 31st, etc.)
- lya=leap year adjustment, which can be done once for each year and
- used later. For Years from 1901-2099, lya=-14.
-
- The value, d, returned is teh day of the week, from 0-6, where 0=Sunday.
- the int(...) means integer division, so in Pascal, drop the int and replace the
- division with a div.
-
- This formula works - I use in a perpetual calendar program I wrote in C.
- Never failed yet. But always test it out on today to be sure.
-
- J.L.Fincher, Warlok
-