Path: utzoo!attcan!uunet!van-bc!ubc-cs!cheddar.ucs.ubc.ca!buckland From: buckland@cheddar.ucs.ubc.ca (Tony Buckland) Newsgroups: comp.lang.c Subject: Re: Date functionality Message-ID: <8931@ubc-cs.UUCP> Date: 30 Jul 90 18:17:28 GMT References: <171@ittc.wec.com> Sender: news@cs.ubc.ca Reply-To: buckland@cheddar.ucs.ubc.ca (Tony Buckland) Organization: UBC Computing Centre, Vancouver, B.C., Canada Lines: 18 In article <171@ittc.wec.com> fbresz@ittc.wec.com writes: >Hello, > I am looking for an algorithm to give me the day of the week when >handed the current date. I can't use any builtin routines from any OS >(this is targeted for a real brain-damaged machine). Any Help appreciated. Answering this question was my first post, a few months ago. Let's see if I can get it right this time. The statement function following will work: DOW(ID,IM,IC,IY)=MOD((26*IM-2)/10+ID+IY+IY/4+IC/4-2*IC,7) where ID is the day of the month, IM is two less than the month from March on (March is 1, ..., December is 10) or 11 for January or 12 for February, IC is the century and IY is the year. The value of DOW is minus one for Saturday, 0 for Sunday, ..., 5 for Friday. At least, it is if I read the program comments correctly this time. It won't work before 1753.