Date conversion question
authorplaceholder at tiger.UUCP.UUCP
authorplaceholder at tiger.UUCP.UUCP
Wed Mar 11 02:37:00 AEST 1987
I pulled this off of the net a few years ago so here it is
again. No flames about this belonging in net.sources.
/*
* test as
* zeller month day year
* year in 1987 form
*/
main(argc,argv)
int argc;
char *argv[];
{
char *zeller();
char *day;
day = zeller(atoi(argv[1]), atoi(argv[2]), atoi(argv[3]));
printf("Day = %s\n",day);
exit(0);
}
/****************************************************************
Compute day of week given any date. Year passed as e.g. 1984.
Algorithm by Zeller.
****************************************************************/
char *
zeller (m,d,y)
int m,d,y; {
static char *day_wk[] =
{ "Sun","Mon","Tue","Wed","Thu","Fri","Sat" };
int y0, y1, y2, m1;
int dbuf;
m1 = ((m+9) % 12) + 1;
y0 = (m <= 2)?(y-1):y;
y1 = y0 / 100;
y2 = y0 % 100;
dbuf = ( (26*m1-2)/10 + d + y2 + y2/4 + y1/4 - 2*y1 ) % 7;
if (dbuf < 0) dbuf += 7;
return day_wk[dbuf];
}
More information about the Comp.unix.wizards
mailing list