home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / lang / pascal / 6649 < prev    next >
Encoding:
Text File  |  1992-11-17  |  1.7 KB  |  51 lines

  1. Newsgroups: comp.lang.pascal
  2. Path: sparky!uunet!mcsun!sun4nl!star.cs.vu.nl!sbakker
  3. From: sbakker@cs.vu.nl (Bakker S)
  4. Subject: Re: Day of week on a given date
  5. Message-ID: <BxuzII.LJ8@cs.vu.nl>
  6. Sender: news@cs.vu.nl
  7. Organization: Fac. Wiskunde & Informatica, VU, Amsterdam
  8. References: <1992Nov17.042319.29002@cs.unca.edu>
  9. Date: Tue, 17 Nov 1992 11:49:29 GMT
  10. Lines: 39
  11.  
  12. snodgras@cs.unca.edu (Ryan Snodgrass) writes:
  13.  
  14. >Does anyone know how to get the day of week given a specified date,
  15. >for example if the function were passed the date "11-16-92" then it would
  16. >return some number representing Monday? (I assume 1)
  17.  
  18. >If you could give me an example, or of where to look to get an example I
  19. >would really appreciate it.
  20.  
  21. That's easy!
  22.  
  23. function WeekDay(y,m,d : word) : byte;
  24. var
  25.     c : word;
  26. begin               {y=year,m=month,d=day,c=century}
  27.     if m<=2 then
  28.     begin
  29.         dec(y);
  30.         inc(m,12)
  31.     end;
  32.     c:=y div 100;
  33.     y:=y mod 100;
  34.     WeekDay := ( 5*c + c div 4 + y + y div 4 + 26*(m+1) div 10  + d-1 ) mod 7;
  35. end;
  36.  
  37. Now if WeekDay returns 0 then it's a Sunday, 1 means Monday, etc.
  38.  
  39.                     Good luck,
  40.                     Dominique & Steven.
  41.  
  42. [=============================================================================]
  43. | Steven Bakker, Vrije Universiteit Amsterdam.                      |
  44. | sbakker@cs.vu.nl                                             |
  45. [-----------------------------------------------------------------------------]
  46. | ".. if a tree falls in the woods, and there's no one there to hear it, does |
  47. | it fall upwards or downwards. And its corollary, if a deaf man falls in the |
  48. | woods, does he make a sound?"                              |
  49. |                    -- Captain Rick.              |
  50. [=============================================================================]
  51.