March 15, 2011

How to determine The day of The week, given The month, day and year?


How to determine The day of The week, given The month, day and year?

The information below was lifted from the from the following web site: http://www.cs.uu.nl/wais/html/na-dir/sci-math-faq/dayofweek.html

   First a brief explanation: in The Gregorian Calendar, over a period of four hundred years, there are 97 leap years and 303 normal years. Each
 normal year, The day of January 1 advances by one; for Each leap year  it advances by two.
  
   303 + 97 + 97 = 497 = 7 * 71
  
   as a result, January 1 year N occurs on The same day of The week as January 1 year N + 400. Because The leap year pattern also recurs with a four hundred year cycle, a simple table of four hundred elements, and single modulus, suffices to determine The day of The week (in The
   Gregorian Calendar), and does it much faster than all The other algorithms proposed. also, Each element takes (in principle) only three bits; The entire table thus takes only 1200 bits; on many computers this will be less than The instructions to do all The complicated calculations proposed or The other algorithms.
 
   Incidental Note: Because 7 does not Divide 400, January 1 occurs more frequently on some days than others! Trick your friends! in a cycle of 400 years, January 1 and March 1 occur on The following days with The following frequencies:  
           Sun      Mon     Tue     Wed     Thu     Fri     Sat
    Jan 1: 58       56      58      57      57      58      56
    Mar 1: 58       56      58      56      58      57      57

   Of interest is that (contrary to most initial guesses) The occurrence is not maximally flat.
  
In The Mathematical Gazette, vol. 53,, pp.127-129, it is shown that The 13th of The month is more likely to be a Friday than any other day.The author is a 13 year old S.R.Baxter.
  
   The Gregorian Calendar was introduced in 1582 in parts of Europe; it was adopted in 1752 in Great Britain and its colonies, and on various dates in other countries. it replaced The Julian Calendar which has a four-year cycle of leap years; after four years January 1 has advanced by five days. Since 5 is relatively prime to 7, a table of 4 * 7 = 28 elements is necessary for The Julian Calendar.
  
   there is still a 3 day over 10,000 years error which The Gregorian Calendar does not take into account. At some Time such a correction will have to be done but your software will probably not last that long!
  
   Here is a standard method suitable for mental computation:
  
    1. take The last two digits of The year.
    2. Divide by 4, discarding any fraction.
    3. Add The day of The month.
    4. Add The month'S key value: JFM AMJ JAS OND 144 025 036 146
    5. Subtract 1 for January or February of a leap year.
    6. For a Gregorian Date, Add 0 for 1900'S, 6 for 2000'S, 4 for 1700'S, 2 for 1800'S; for other years, Add or Subtract multiples of 400.
    7. For a Julian Date, Add 1 for 1700'S, and 1 for every additional century you go back.
    8. Add The last two digits of The year.
    9. Divide by 7 and take The remainder.
      
   Now 1 is Sunday, The First day of The week, 2 is Monday, and so on.
  
   The following formula, which is for The Gregorian Calendar only, may be more convenient for computer programming. Note that in some programming languages The remainder operation can yield a negative result if given a negative operand, so mod 7 may not translate to a simple remainder.
  
   W = (k + floor(2.6m - 0.2) - 2C + Y + floor(Y/4) + floor(C/4)) mod 7
  
   where floor() denotes The integer floor function [This is TRN() in Logix],
k is day (1 to 31)
 m is month (1 = March, ..., 10 = December, 11 = Jan, 12 = Feb) Treat Jan & Feb as months of The preceding year
   C is century (1987 has C = 19)
   Y is year (1987 has Y = 87 except Y = 86 for Jan & Feb)
   W is week day (0 = Sunday, ..., 6 = Saturday)
  
   Here The century and 400 year corrections are built into The formula. The floor(2.6m - 0.2) term relates to The repetitive pattern that The 30-day months show when March is taken as The First month.
  
   The following short C program works for a restricted range, it returns 0 for Monday, 1 for Tuesday, etc.
  
dow(m,d,Y){Y-=m<3;return(Y+Y/4-Y/100+Y/400+[m]+d)%7;}

   The program appeared was posted by sakamoto@sm.sony.co.jp (Tomohiko sakamoto) on comp.lang.c on March 10th, 1993.
   
   a good mnemonic rule to help on The computation of The day of The week is as follows. in any given year The following days come on The same day of The week: 4/4, 6/6, 8/8, 10/10, 12/12  to remember The next four, remember that I work from 9-5 At a 7-11 so 9/5, 5/9, 7/11, 11/7 and The last day of Feb.
  
  
  
   Even ignoring The pattern over for a period of years this is still useful Since you can generally figure out what day of The week a given Date is  on faster than someone else can look it up with a calender if The calender is not right there. (a useful skill that.)
  
 References:     
   Winning Ways for your Mathematical plays. Elwyn R. Berlekamp, John H.  Conway, and Richard k. Guy London ; Toronto : Academic Press, 1982.
 
   Mathematical Carnival. Martin Gardner. New York : Knopf, c1975.  
   Elementary Number Theory and its applications. Kenneth Rosen. Reading,  Mass. ; Don Mills, Ont. : Addison-Wesley Pub. Co., c1993. p. 156.
  
   Michael Keith and Tom Craver. The Ultimate Perpetual Calendar? Journal of Recreational Mathematics, 22:4, pp. 280-282, 19

Disclaimer:
The above article doesn't give you any guarantee and the sole purpose of this article is to share my learning in the way I understood. Any comments to refine this article are welcome with great pleasure. Please report any breaking link by commenting below.

No comments:

Post a Comment

Comment will be published after moderation only. Do not advertise here.

Receive all updates via Facebook. Just Click the Like Button Below

You can also receive Free Email Updates:

dgpride - Study Zone - Free Books - Tamil Lyrics

Copyright © 2008 -2012 dgpride. All rights reserved.

Subject/Topics

2 Marks (26) 8051 (1) AC Machines (7) Animations (1) Anna University Chennai (31) Arduino (4) ARM (3) Audio (1) Basic C Concepts (8) Basic Electronics (13) Basic principles (9) Book list (1) CAD (1) Chemical (2) Circuit theory (6) Civil (2) Cloud Computing (1) Communication (4) Competitive exams (2) Computer Architecture (4) Control system and components (9) CSE (40) Curriculum (4) DC Machines (9) Did you know (14) Digital (13) DLC (4) Documentation (1) DSP (1) EC 2201 (3) ECE (45) EDC (1) EEE (34) EIE (63) Electrical (35) Electronics (43) Electroplating (2) Emacs (1) Embedded basics (19) Embedded C Programming (19) Embedded Linux (5) Embedded System (22) Engineering basics (15) Environmental Science (1) Fibre Optics (1) Filters (2) FPGA (1) GATE (3) General (7) GNU (4) Handwritten (1) Hobbyist (15) How to (8) HTML (3) Humanities (2) IC Engines (7) ICE (5) Industrial Electronics (10) Industrial Instrumentatin (2) industrial process (2) Instrumentation (21) IoT (2) IT (2) Laboratory Manuals (17) LabVIEW (2) Lesson notes (2) LIC (2) Links (9) Linux (8) Magnetics (1) Management (1) Mechanical (5) Mechatronics (9) Microcontrollers (14) Microprocessors (9) Microsoft (1) Motivation (1) Must Know (11) Networks (1) NuttX (1) Objective type (1) Open Source (1) Opportunities (7) Oscillators (2) Part Time (1) Physics (1) Post Graduation (1) Power Electronics (12) Power Plant Engineering (2) Power Supplies (2) Previous GATE Papers (1) Process Control (2) Project (4) Protocol (1) R2008 (11) R2009 (1) R2013 (1) Recruitment (2) Research (2) Robotics (9) RTOS (3) Signal Processing (8) Signals and Systems (4) SMPS (1) Software tutorial (4) Stepper Motor (2) Syllabus (5) Texas Instruments (2) Thermodynamics (2) Training and Placement (6) Transducer Engineering (2) Transformer (2) Transmission (1) Tutorials (48) Two Marks (26) U-Boot (1) University Question Papers (16) Verilog (1) Video (4) Virtual Instrumentation (3) Visual Basic (21) VLSI (11) Web designing (4) Wi-Fi (3) Wireless (6)