Path: utzoo!mnetor!uunet!lll-winken!lll-lcc!ames!sdcsvax!nosc!humu!uhmanoa!uhccux!julian From: julian@uhccux.UUCP (Julian Cowley) Newsgroups: comp.sys.ibm.pc Subject: Re: day of week Message-ID: <1510@uhccux.UUCP> Date: 2 Feb 88 11:19:39 GMT References: <141900013@occrsh.ATT.COM> <3170@killer.UUCP> Organization: U. of Hawaii, Manoa (Honolulu) Lines: 35 Summary: another formula Here is a formula that I picked out of an old HP-2000 calendar program. Basically it figures out how many days there are since January 1, 1900. As that date was a Monday, the result modulo 7 starts on that day of the week. This should work for all of the years in this century, with the exception of 1900 because that year was not a leap year. Sample C program: char *daystr[7] = { "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday" }; main() { int day, year, month, date; puts("Enter the date as mm/dd/yy"); scanf("%d/%d/%d", &month, &date, &year); day = ((year-1)*365 + (year-1)/4 + (int) ((month-1)*30.57+0.5) - (1+(year%4 != 0))*(month > 2) + date) % 7; printf("That day was a %s\n", daystr[day]); } Cheers. ////// ///// Julian Cowley, University of Hawaii | "It's not the size of // // // ...!ihnp4!sdcsvax!nosc!uhccux!julian | the disk that matters, \\ // // julian@uhccux.uhcc.hawaii.edu | it's the way it's \X/ ///// julian@uhccux.bitnet | formatted..."