Date functionality

Tony Buckland buckland at cheddar.ucs.ubc.ca
Tue Jul 31 04:17:28 AEST 1990


In article <171 at ittc.wec.com> fbresz at 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.



More information about the Comp.lang.c mailing list