2009-03-13

Vacation

Just starting my winter holiday. Next month there are also days free from work. Easter is coming. The date of easter is moving around. Found an algorithm from wikipedia for counting the day of easter sunday. Here is an implementation of Butchers method in SQL:


select to_date((p+1)||'-'||n||'-'||vu,'dd-mm-yyyy')
from (
select vu, a, b, c, d, e, f, g, h, i, k, l, m, trunc((h+l-7*m+114)/31) as n, mod(h+l-7*m+114,31) as p
from (
select vu, a, b, c, d, e, f, g, h, i, k, l, trunc((a+11*h+22*l)/451) as m
from (
select vu, a, b, c, d, e, f, g, h, i, k, mod(32+2*e+2*i-h-k,7) as l
from (
select vu, a, b, c, d, e, f, g, mod(19*a+b-d-g+15,30) as h, trunc(c/4) as i, mod(c,4) as k
from (
select vu, a, b, c, d, e, f, trunc((b-f+1)/3) as g
from (
select vu, a, b, c, trunc(b/4) as d, mod(b,4) as e, trunc((b+8)/25) as f
from (
select vu, mod(vu,19) as a, trunc(vu/100) as b, mod(vu,100) as c
from (
select level+1999 vu
from dual connect by level <= 20 
) ) ) ) ) ) ) )
;

No comments:

Post a Comment

About Me

My photo
I am Timo Raitalaakso. I have been working since 2001 at Solita Oy as a Senior Database Specialist. I have received Oracle ACE nomination. My main focus is on projects involving Oracle database. In this Rafu on db blog I write some interesting issues that evolves from my interaction with databases. Mainly Oracle.