jdcrowe

easter dates

Feb 9th, 2018 (edited)
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
T-SQL 1.28 KB | None | 0 0
  1. with [Years] as ( /*Generate list of years between 1900 and 2099*/
  2.     select (ones.n + 10 * tens.n + 100 * hundreds.n + 1000 * thousands.n) [Year]
  3.     from
  4.         (values(0),(1),(2),(3),(4),(5),(6),(7),(8),(9)) ones(n)
  5.         , (values(0),(1),(2),(3),(4),(5),(6),(7),(8),(9)) tens(n)
  6.         , (values(0),(1),(2),(3),(4),(5),(6),(7),(8),(9)) hundreds(n)
  7.         , (values(0),(1),(2),(3),(4),(5),(6),(7),(8),(9)) thousands(n)
  8.     where (ones.n + 10 * tens.n + 100 * hundreds.n + 1000 * thousands.n) between 1900 and 2099
  9. ), [EasterDates] as ( /*Calculate Easter's Date from Year, https://en.wikipedia.org/wiki/Computus*/
  10.     select (
  11.         select (convert(date, rtrim([Year]) + '0' + rtrim([Month]) + right('0' + rtrim([Day]),2))) [Date]
  12.         from (
  13.             select [Month], ([DaysToSunday] + 28 - (31 * ([Month] / 4))) [Day]
  14.             from (
  15.                 select (3 + ([DaysToSunday] + 40) / 44) [Month], [DaysToSunday]
  16.                 from (
  17.                     select ([Paschal] - (([Year] + [Year] / 4 + [Paschal] - 13) % 7)) [DaysToSunday]
  18.                     from (
  19.                         select ([Epact] - ([Epact] / 28)) [Paschal] /*https://en.wikipedia.org/wiki/Paschal_full_moon*/
  20.                         from (
  21.                             select ((24 + 19 * ([Year] % 19)) % 30) [Epact] /*https://en.wikipedia.org/wiki/Epact*/
  22.                         ) as e
  23.                     ) as p
  24.                 ) as dts
  25.             ) as m
  26.         ) as d) [Date]
  27.     from [Years]
  28. )
  29. select * from [EasterDates]
Add Comment
Please, Sign In to add comment