Please create an account to participate in the Slashdot moderation system

 



Forgot your password?
typodupeerror
User Journal

joke_dst's Journal: SQL function for calculating easter date

Journal by joke_dst

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

This discussion has been archived. No new comments can be posted.

SQL function for calculating easter date

Comments Filter:

"In my opinion, Richard Stallman wouldn't recognise terrorism if it came up and bit him on his Internet." -- Ross M. Greenberg

Working...