Date-Routines for C/UNIX ? HELP
Christopher Lott
cml at tove.umd.edu
Wed Sep 13 23:32:21 AEST 1989
In article <207600039 at s.cs.uiuc.edu> mccaugh at s.cs.uiuc.edu writes:
>
> I tried mailing to Mathias, but no luck...anyway, here (at least) is the
> C code for day-of-week given the date as MMDDYYYY:
>......
I was sent this function some time ago. The author's name appears below.
Seems to work very well, and is nice and short.
I have not tested it extensively. If someone can tell me more about the
below-referenced "Zeller" function, I'd appreciate it.
>From pats at cup.portal.com Thu Jun 29 10:27:56 1989
From: pats at cup.portal.com (Pat T Shea)
Newsgroups: comp.sys.ibm.pc
Subject: Re: calendar code
Date: 29 Jun 89 00:19:58 GMT
Organization: The Portal System (TM)
'think this is what ur looking for. . . . /pats.
/***********************************************************************
*
* int dmy2dow( int iDay, int iMon, int iYear ) - This is my
* implementation of the Zeller function. It takes day/
* month/year and returns the day of the week as an int
* with Sunday being 0.....etc.
* /pats @Psi!
* 11/05/85
******/
int dmy2dow( int day, int mon, int year )
{
int adj_mo, adj_yr, cent, cent_yrs;
adj_mo = ( mon > 2 ) ? mon - 2 : mon + 10;
adj_yr = ( mon > 2 ) ? year : year - 1;
cent = adj_yr / 100;
cent_yrs = adj_yr % 100;
return((((( 13 * adj_mo - 1 ) / 5 ) + day + cent_yrs +
( cent_yrs / 4 ) + ( cent / 4 ) - 2 * cent + 77 ) % 7 ));
}
Hope this is useful to someone.
chris...
cml at tove.umd.edu Computer Science Dept, U. Maryland at College Park
4122 A.V.W. 301-454-8711 <standard disclaimers>
More information about the Comp.lang.c
mailing list