Beta

Slashdot: News for Nerds

×

Thank you!

Before you choose to head back to the Classic look of the site, we'd appreciate it if you share your thoughts on the Beta; your feedback is what drives our ongoing development.

Beta is different and we value you taking the time to try it out. Please take a look at the changes we've made in Beta and  learn more about it. Thanks for reading, and for making the site better!

SQL function for calculating easter date

joke_dst (832055) writes | more than 6 years ago

0

A SQL function to calculate the easter date on any given year:

create function getEasterDate( @yr int )
returns datetime
As Begin

declare @g int, @c int, @x int, @z int, @d int, @e int, @n int

A SQL function to calculate the easter date on any given year:

create function getEasterDate( @yr int )
returns datetime
As Begin

declare @g int, @c int, @x int, @z int, @d int, @e int, @n int

set @g = @yr % 19 + 1
set @c = @yr / 100 + 1
set @x = (3 * @c) / 4 - 12
set @z = (8 * @c + 5) / 25 - 5
set @d = (5 * @yr) / 4 - @x - 10
set @e = (11 * @g + 20 + @z - @x) % 30

if (@e = 24) or ((@e = 25) and (@g > 11)) set @e = @e + 1

set @n = 44 - @e
if (@n 31 begin
set @g = 4
set @n = @n-31
end

return cast( cast(@yr as varchar) + '-' + cast(@g as varchar) + '-' + cast(@n as varchar) as datetime)
End

cancel ×

Slashdot Account

Need an Account?

Don't worry, we never post anything without your permission.

Submission Text Formatting Tips

We support a small subset of HTML, namely these tags:

• b
• i
• p
• br
• a
• ol
• ul
• li
• dl
• dt
• dd
• em
• strong
• tt
• blockquote
• div
• quote
• ecode

"ecode" can be used for code snippets, for example:

``<ecode>    while(1) { do_something(); } </ecode>``
Create a Slashdot Account