home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.pascal
- Path: sparky!uunet!mcsun!sun4nl!star.cs.vu.nl!sbakker
- From: sbakker@cs.vu.nl (Bakker S)
- Subject: Re: Day of week on a given date
- Message-ID: <BxuzII.LJ8@cs.vu.nl>
- Sender: news@cs.vu.nl
- Organization: Fac. Wiskunde & Informatica, VU, Amsterdam
- References: <1992Nov17.042319.29002@cs.unca.edu>
- Date: Tue, 17 Nov 1992 11:49:29 GMT
- Lines: 39
-
- 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.
-
- That's easy!
-
- function WeekDay(y,m,d : word) : byte;
- var
- c : word;
- begin {y=year,m=month,d=day,c=century}
- if m<=2 then
- begin
- dec(y);
- inc(m,12)
- end;
- c:=y div 100;
- y:=y mod 100;
- WeekDay := ( 5*c + c div 4 + y + y div 4 + 26*(m+1) div 10 + d-1 ) mod 7;
- end;
-
- Now if WeekDay returns 0 then it's a Sunday, 1 means Monday, etc.
-
- Good luck,
- Dominique & Steven.
-
- [=============================================================================]
- | Steven Bakker, Vrije Universiteit Amsterdam. |
- | sbakker@cs.vu.nl |
- [-----------------------------------------------------------------------------]
- | ".. if a tree falls in the woods, and there's no one there to hear it, does |
- | it fall upwards or downwards. And its corollary, if a deaf man falls in the |
- | woods, does he make a sound?" |
- | -- Captain Rick. |
- [=============================================================================]
-