home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / lang / c / 18348 < prev    next >
Encoding:
Internet Message Format  |  1992-12-15  |  1.5 KB

  1. Xref: sparky comp.lang.c:18348 comp.lang.pascal:7465 comp.lang.c++:17944
  2. Newsgroups: comp.lang.c,comp.lang.pascal,comp.lang.c++
  3. Path: sparky!uunet!elroy.jpl.nasa.gov!swrinde!zaphod.mps.ohio-state.edu!darwin.sura.net!spool.mu.edu!yale.edu!yale!gumby!destroyer!sol.ctr.columbia.edu!eff!news.byu.edu!ux1!fcom.cc.utah.edu!park.uvcc.edu!ns.novell.com!novdpd!novell.com!jhaide
  4. From: jhaide@novell.com (Janos A. Haide)
  5. Subject: Re: Date -> Day of week conversion
  6. Message-ID: <jhaide.22.724104190@novell.com>
  7. Lines: 31
  8. Sender: news@novell.com
  9. Nntp-Posting-Host: aus-jhaide
  10. Organization: Novell, Inc. --Austin
  11. References: <Bz3I8K.LDJ@ccu.umanitoba.ca>
  12. Date: Fri, 11 Dec 1992 20:03:10 GMT
  13.  
  14. In article <Bz3I8K.LDJ@ccu.umanitoba.ca> ummalik@ccu.umanitoba.ca (Ijaz Rashid Malik) writes:
  15. >
  16. >Could someone please forward me algorithm to convert the date (in dd.mm.yy
  17. >or yy.mm.dd format, but assume individual fields can be obtained as integers)
  18. >to corresponding day of the week.
  19. >
  20. >Thanks very much.
  21. >
  22. >Malik
  23.  
  24. Since you have crossposted in comp.lang.c I'd say that you can simply
  25. initialize a few fields on a struct tm and then apply mktime() on it.
  26. One of the fields will be set to the week of day. 
  27.  
  28. As far as a generic formula goes, here is one I've seen a few days ago 
  29. (PASCAL-ish):
  30.  
  31. N:=(Trunc(M*2.6-0.1)+D+Y+Y div 4+5*C+C div 4) mod 7
  32.  
  33. Where:
  34. D = day of month
  35. Y = year of the century.
  36. C = century.
  37. M = Month - 2.
  38.     ( January M=11 , February M=12 )
  39.  
  40. Result is an 0-6 integer.
  41.  
  42. Later,
  43. Janos
  44. jhaide@novell.com
  45.