home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / lang / pascal / 6791 < prev    next >
Encoding:
Internet Message Format  |  1992-11-21  |  1.6 KB

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