Very nice collection of algorithms, Jeffrey. I've got one more for you to add to your collection.
Peter "Peso" Larsson came up with the following basic method quite a while back. Apparently, he pre-calculated the dates for the 19 year cycle of the moon and calculates the following Sunday. I've not verified the method all the way out to 9999 but have verified it for the previous, current, and next centuries.
The first link below is where Peter originally published it and the second link is a "near enough" explanation although it uses a couple of tables to calculate the base date and the offsets instead of the simple integer math and "find a Sunday" date trick the we've all grown to know and love. Here's Peter's code with a little "Modenization" to reduce the clock cycles a bit and turn it into an iSF (iTVF that returns a scalar value).
CREATE OR ALTER FUNCTION dbo.GetEasterDate
RETURNS TABLE AS
SELECT EasterDate = DATEADD(DAY,DATEDIFF(DAY,0,@Year+v.BaseDate)/7*7,6) --Finds Sunday after BaseDate
) v (Cycle,BaseDate)
WHERE @Year BETWEEN '1900' AND '9999'
AND v.Cycle = @Year%19
is pronounced "ree-bar
" and is a "Modenism
" for R
First step towards the paradigm shift of writing Set Based code:
________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.
"Change is inevitable... change for the better is not".
"If "pre-optimization" is the root of all evil, then what does the resulting no optimization lead to?"
How to post code problems
How to Post Performance Problems
Create a Tally Function (fnTally)