Advertisement
whited24

Day of Week

Oct 15th, 2011
463
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <!--- W=C+Y+L+M+D (mod 7) --->
  2. <!---
  3.    W is the day of the week (0=Sunday, through 6=Saturday)
  4.    C is a code for the century from this table (for the Gregorian calendar only):
  5.     1400s, 1800s, 2200s     2       1800 is not a leap year
  6.     1500s, 1900s, 2300s     0       1900 is not a leap year
  7.     1600s, 2000s, 2400s     5       2000 is a leap year
  8.     1700s, 2100s, 2500s     4       2100 is not a leap year
  9.    Y is the last two digits of the year.
  10.    L is the number of leap days since the beginning of the century.
  11.         Step1 : Divide the year (two digits) by 4 and throw away the fraction.
  12.         Step 2: Notice that 1900 and 1800 were not leap years, and 2000 was.
  13.                 Only century years divisible by 400 are leap years.
  14.                 So, add 1 for those centuries divisible by 4 (as we haven't counted the leap day for year 00 yet).
  15.         Step 3: Also, don't count a leap day if it happens after the date that you are calculating.
  16.                 In other words subtract one, if you are calculating a date of January or February of a leap year.
  17.    M is the code for the month, from this table:
  18.     1. Jan.     0       5. May      1        9. Sep.    5
  19.     2. Feb.     3       6. June     4       10. Oct.    0
  20.     3. Mar.     3       7. July     6       11. Nov.    3
  21.     4. Apr.     6       8. Aug.     2       12. Dec.    5
  22.    D is the date.
  23.    
  24.     Let's try 20/07/1969. We get 0+69+17+6+20 (mod 7) which is 0 (divide by 7 and get a 0 remainder), or Sunday.
  25. --->
  26.  
  27. <cfset listCenturies = '0,0,0,0,0,0,0,0,0,0,0,0,0,2,0,5,4,2,0,5,4,2,0,5,4'>
  28. <cfset listMonths = '0,3,3,6,1,4,6,2,5,0,3,5'>
  29. <cfset listDays = 'Sun,Mon,Tue,Wed,Thu,Fri,Sat'>
  30. <cfset strDay = '01'>
  31. <cfset strMonth = '02'>
  32. <cfset strYear = '2006'>
  33. <cfset intDay = int(strDay)>
  34. <cfset intMonth = int(strMonth)>
  35. <cfset intYear = int(strYear)>
  36. <cfset blnLeapYear = false>
  37. <cfset strCentury = Left(strYear,2) + '00'>
  38. <cfset intCentury = int(strCentury)>
  39. <cfset L = 0>
  40. <cfset Y = int(Right(strYear,2))>
  41. <cfset C = ListGetAt(listCenturies,int(Left(strYear,2)))>
  42. <cfset M = ListGetAt(listMonths,intMonth)>
  43. <cfset D = intDay>
  44. <cfset intModifier = 0>
  45. <!--- CALCULATE THE NUMBER OF LEAP DAYS SINCE THE START OF THE CURRENT CENTURY  --->
  46. <cfloop from="#intCentury#" to="#intYear#" index="idxYearCount">
  47.     <cfif IsLeapYear(idxYearCount) and idxYearCount neq 2000>
  48.         <cfset L = L + 1>
  49.     </cfif>
  50. </cfloop>
  51. <!--- IF THE CURRENT MONTH IS JAN OR FEB THEN SUBSTRACT ONE ( AS IS SPECIFIED IN THE NOTES AT THE TOP OF THE PAGE) --->
  52. <cfif intMonth eq 1 or intMonth eq 2>
  53.     <cfset L = L - 1>
  54. </cfif>
  55. <cfset W = ((C + Y + L + M + D) mod 7) - 1>
  56. <cfif W eq -1>
  57.     <cfset W = 6>
  58. </cfif>
  59. <cfoutput>
  60. My Day of Week = #W#<br>
  61. My Day of Week String = #ListGetAt(listDays,W + 1)#<br>
  62. </cfoutput>
  63.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement