Want to read Slashdot from your mobile device? Point it at m.slashdot.org and keep reading!

 



Forgot your password?
typodupeerror
×
User Journal

Journal joke_dst's Journal: SQL function for calculating easter date

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:

Without life, Biology itself would be impossible.

Working...