Function to return date of Easter for the given year

前端 未结 8 1423
眼角桃花
眼角桃花 2020-12-08 05:12

So, here\'s a funny little programming challenge. I was writing a quick method to determine all the market holidays for a particular year, and then I started reading about E

8条回答
  •  轮回少年
    2020-12-08 05:29

    Found this Excel formula somewhere
    Assuming cell A1 contains year e.g. 2020

    ROUND(DATE(A1;4;1)/7+MOD(19*MOD(A1;19)-7;30)*0,14;0)*7-6
    

    Converted to T-SQL lead me to this:

    DECLARE @yr INT=2020
    SELECT DATEADD(dd, ROUND(DATEDIFF(dd, '1899-12-30', DATEFROMPARTS(@yr, 4, 1)) / 7.0 + ((19.0 * (@yr % 19) - 7) % 30) * 0.14, 0) * 7.0 - 6, -2)
    

提交回复
热议问题