Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!gem.mps.ohio-state.edu!samsung!caesar.cs.montana.edu!ogccse!orstcs!jacobs.CS.ORST.EDU!moorer From: moorer@jacobs.CS.ORST.EDU (Rocky Moore) Newsgroups: comp.lang.c Subject: Re: Day of week algorithm wanted for "C" Message-ID: <13902@orstcs.CS.ORST.EDU> Date: 20 Nov 89 15:54:29 GMT References: <1031@icus.islp.ny.us> Sender: usenet@orstcs.CS.ORST.EDU Reply-To: moorer@jacobs.CS.ORST.EDU.UUCP (Rocky Moore) Distribution: usa Organization: Oregon State University - CS - Corvallis Oregon Lines: 28 In article <1031@icus.islp.ny.us> lenny@icus.islp.ny.us (Lenny Tropiano) writes: >I need a function that accepts a month, a day, and a year ... and returns >the day-of-the-week (ie. Sunday, Monday, etc..) Here is a little piece of code I pulled out of the time routine I use. It will return a value 0-6 where 0=Sunday, 1=Monday, ect... --- CUT HERE --- /* Find and return day of week (0-6) */ int day_of_week(int year, int month, int day) { 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); } --- END --- This should handle what you want. Hope it helps. Rocky Moore moorer@jacobs.cs.orst.edu