Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uunet!sdrc!scjones From: scjones@sdrc.UUCP (Larry Jones) Newsgroups: comp.sys.ibm.pc Subject: Re: I need a date :) please help Message-ID: <1268@sdrc.UUCP> Date: 8 Apr 90 14:27:33 GMT References: <19500060@uxh.cso.uiuc.edu> Organization: SDRC, Cincinnati Lines: 31 In article <19500060@uxh.cso.uiuc.edu>, mead@uxh.cso.uiuc.edu writes: > QUERY: Does anyone know of *any* source for an intelligent algorythm > for getting the day ('Monday, Tuesday, ...') from the date (4/3/90). > My PC does it like lightning each time I issue the 'DATE' command, and > if IBM can do it, anyone can - right? :) Textbooks or whatever are > fine, but please don't direct me to existing software unless it's PD > source code (in BASIC, C, Pascal, or FORTRAN). Thanks. The traditional algorithm is (in C): weekday = (year + year/4 + startday[month-1] + day) % 7; if (year%4 == 0 && month < 3) --weekday; year is either the full year or the last two digits, month is the month (1 - 12), and day is the day of the month (1 - 31). startday is a table of the day of the week each month starts on (in a non-leap year). Start by looking at a calendar and using the day of the week each month starts on (0=Sunday, 7=Saturday). Then, try an example and adjust all the table entries to get the correct result. (For example, if the date you try is a Tuesday (2) and the equation gives you Friday (6), then you need to subtract 4 (6-2) from each entry in the table. If the result is negative, just add 7.) ---- Larry Jones UUCP: uunet!sdrc!scjones SDRC scjones@SDRC.UU.NET 2000 Eastman Dr. BIX: ltl Milford, OH 45150-2789 AT&T: (513) 576-2070 "You know how Einstein got bad grades as a kid? Well MINE are even WORSE!" -Calvin