mike@ntmtka.mn.org (Mike Tietel) (12/05/89)
I know there exists an algorithm to compute the day of the week, given the month, day and year. For example, what day of the week is September 13, 1998? Does anyone know where I can find the algorithm, or alternatively, where I can find its "C" implementation??? Thanks in advance... -- Mike Tietel Northern Telecom, Inc. (612) 932-8017 9701 Data Park, S-100 mike@ntmtka.mn.org Minnetonka, MN 55343 uunet!rosevax!ntmtka!mike
rickf@pmafire.UUCP (rick furniss) (12/07/89)
#include <stdio.h> main (argc,argv) char **argv; int argc; { int result; int year=atoi(argv[1]), month=atoi(argv[2]), day=atoi(argv[3]); if (argc != 4 ) { fprintf(stderr,"Usage: %s YY MM DD\n",argv[0]); exit(1); } result=day_of_week(year,month,day); fprintf(stdout,"day # %i\n",result); exit(0); } /* Find and return day of week (0-6) */ int day_of_week(year,month,day) int year,month,day; { static int offsets[13] = { 0,0,3,3,6,1,4,6,2,5,7,3,5 }; int dw; dw=6+year+((year+3)/4)+offsets[month]+day; if( ((year%4) ==0) && (month > 2)) dw++; if( (year==0) && (month < 3)) dw++; dw=(dw%7); return(dw); } Standard disclaimer ******* Rick Furniss
c9h@psuecl.bitnet (12/07/89)
In article <890@pmafire.UUCP>, rickf@pmafire.UUCP (rick furniss) writes: > [program to calculate day of week] This will work find. Until the year 2100. Remember that only every *fourth* century year is a leap year. -- - Charles Martin Hannum II "Klein bottle for sale ... inquire within." (That's Charles to you!) "To life immortal!" c9h@psuecl.{bitnet,psu.edu} "No noozzzz izzz netzzzsnoozzzzz..." cmh117@psuvm.{bitnet,psu.edu} "Mem'ry, all alone in the moonlight ..."
jim@anacom1.UUCP (Jim Bacon) (12/10/89)
In article <1894@ntmtka.mn.org> mike@ntmtka.mn.org (Mike Tietel) writes: >I know there exists an algorithm to compute the day of the week, >given the month, day and year. For example, what day of the week >is September 13, 1998? > >Does anyone know where I can find the algorithm, or alternatively, >where I can find its "C" implementation??? > The book "Common C Functions" published by Que contains a very good section on date manipulation routines including the Zeller congruence routine you are looking for. Source is given in C for the IBM PC, but is portable with little or no change to UNIX. The other routines are for doing Julian conversions and date math. I have found them to be quite useful and have incorporated them into our local library. -- Jim Bacon | "A computer's attention span is only Anacom General Corp., CA | as long as its extension cord." jim@anacom1.cpd.com | zardoz!anacom1!jim | Anon
battle@alphard.cs.utk.edu (David Battle) (12/15/89)
In article <365@anacom1.UUCP> jim@anacom1.UUCP (Jim Bacon) writes: >The book "Common C Functions" published by Que contains a very good >section on date manipulation routines including the Zeller congruence >routine... While we're on the subject, what I would like to get my hands on is the source to the ctime(3) function and the date(1) program, or some reasonable facsimile(s) thereof. In particular, something that handles timezones and daylight savings time. -David L. Battle battle@battle.esd.ornl.gov battle@utkvx2.BITNET
erc@khijol.UUCP (Edwin R. Carp) (12/19/89)
In article <1503@utkcs2.cs.utk.edu> battle@alphard.cs.utk.edu (David Battle) writes: > >While we're on the subject, what I would like to get my hands on is the >source to the ctime(3) function and the date(1) program, or some reasonable >facsimile(s) thereof. In particular, something that handles timezones and >daylight savings time. No, you don't. I've looked at the source for date(1), and it's HORRIBLE. Yuck! You're better off writing your own... --------------------------- discard all after this line ----------------------- Ed Carp N7EKG/5 (28.3-28.5) ...!attctc!puzzle!khijol!erc (home) (512) 832-5884 Snail Mail: 2000 Cedar Bend Dr., #335, Austin, TX 78758 [Disclaimer: The information contained in this message is soley for informa- tional purposes only. Use at your own risk. No warranty expressed or implied.] "You may think you're smart, Pierce, but you're DUMB! Real DUMB! But, you've met your match in ME!" - Col. Flagg "Good tea. Nice house." -- Worf
erc@khijol.uucp@canremote.uucp (erc@khijol.UUCP) (12/21/89)
From: erc@khijol.UUCP (Edwin R. Carp) Orga: Deadly Force, Inc., aka Clint Eastwood School of Diplomacy In article <1503@utkcs2.cs.utk.edu> battle@alphard.cs.utk.edu (David Battle) writes: > >While we're on the subject, what I would like to get my hands on is the >source to the ctime(3) function and the date(1) program, or some reasonable >facsimile(s) thereof. In particular, something that handles timezones and >daylight savings time. No, you don't. I've looked at the source for date(1), and it's HORRIBLE. Yuck! You're better off writing your own... --------------------------- discard all after this line ----------------------- Ed Carp N7EKG/5 (28.3-28.5) ...!attctc!puzzle!khijol!erc (home) (512) 832-5884 Snail Mail: 2000 Cedar Bend Dr., #335, Austin, TX 78758 [Disclaimer: The information contained in this message is soley for informa- tional purposes only. Use at your own risk. No warranty expressed or implied.] "You may think you're smart, Pierce, but you're DUMB! Real DUMB! But, you've met your match in ME!" - Col. Flagg "Good tea. Nice house." -- Worf --- * Via MaSNet/HST96/HST144/V32 - UN C Language * Via Usenet Newsgroup comp.lang.c