Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!--- W=C+Y+L+M+D (mod 7) --->
- <!---
- W is the day of the week (0=Sunday, through 6=Saturday)
- C is a code for the century from this table (for the Gregorian calendar only):
- 1400s, 1800s, 2200s 2 1800 is not a leap year
- 1500s, 1900s, 2300s 0 1900 is not a leap year
- 1600s, 2000s, 2400s 5 2000 is a leap year
- 1700s, 2100s, 2500s 4 2100 is not a leap year
- Y is the last two digits of the year.
- L is the number of leap days since the beginning of the century.
- Step1 : Divide the year (two digits) by 4 and throw away the fraction.
- Step 2: Notice that 1900 and 1800 were not leap years, and 2000 was.
- Only century years divisible by 400 are leap years.
- So, add 1 for those centuries divisible by 4 (as we haven't counted the leap day for year 00 yet).
- Step 3: Also, don't count a leap day if it happens after the date that you are calculating.
- In other words subtract one, if you are calculating a date of January or February of a leap year.
- M is the code for the month, from this table:
- 1. Jan. 0 5. May 1 9. Sep. 5
- 2. Feb. 3 6. June 4 10. Oct. 0
- 3. Mar. 3 7. July 6 11. Nov. 3
- 4. Apr. 6 8. Aug. 2 12. Dec. 5
- D is the date.
- 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.
- --->
- <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'>
- <cfset listMonths = '0,3,3,6,1,4,6,2,5,0,3,5'>
- <cfset listDays = 'Sun,Mon,Tue,Wed,Thu,Fri,Sat'>
- <cfset strDay = '01'>
- <cfset strMonth = '02'>
- <cfset strYear = '2006'>
- <cfset intDay = int(strDay)>
- <cfset intMonth = int(strMonth)>
- <cfset intYear = int(strYear)>
- <cfset blnLeapYear = false>
- <cfset strCentury = Left(strYear,2) + '00'>
- <cfset intCentury = int(strCentury)>
- <cfset L = 0>
- <cfset Y = int(Right(strYear,2))>
- <cfset C = ListGetAt(listCenturies,int(Left(strYear,2)))>
- <cfset M = ListGetAt(listMonths,intMonth)>
- <cfset D = intDay>
- <cfset intModifier = 0>
- <!--- CALCULATE THE NUMBER OF LEAP DAYS SINCE THE START OF THE CURRENT CENTURY --->
- <cfloop from="#intCentury#" to="#intYear#" index="idxYearCount">
- <cfif IsLeapYear(idxYearCount) and idxYearCount neq 2000>
- <cfset L = L + 1>
- </cfif>
- </cfloop>
- <!--- IF THE CURRENT MONTH IS JAN OR FEB THEN SUBSTRACT ONE ( AS IS SPECIFIED IN THE NOTES AT THE TOP OF THE PAGE) --->
- <cfif intMonth eq 1 or intMonth eq 2>
- <cfset L = L - 1>
- </cfif>
- <cfset W = ((C + Y + L + M + D) mod 7) - 1>
- <cfif W eq -1>
- <cfset W = 6>
- </cfif>
- <cfoutput>
- My Day of Week = #W#<br>
- My Day of Week String = #ListGetAt(listDays,W + 1)#<br>
- </cfoutput>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement