返回给定年份复活节日期的函数 [英] Function to return date of Easter for the given year

查看:22
本文介绍了返回给定年份复活节日期的函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,这是一个有趣的小编程挑战.我正在编写一个快速方法来确定特定年份的所有市场假期,然后我开始阅读复活节 并发现确定日期的逻辑是多么疯狂* - Paschal Full 之后的第一个星期日春分之后的月亮!有人知道计算给定年份复活节日期的现有函数吗?

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 Easter and discovered just how crazy* the logic is for determining its date--the first Sunday after the Paschal Full Moon following the spring equinox! Does anybody know of an existing function to calculate the date of Easter for a given year?

当然,这可能并不是所有那么都很难做到;我只是想我会问,以防有人已经这样做了.(这似乎很有可能.)

Granted, it's probably not all that hard to do; I just figured I'd ask in case somebody's already done this. (And that seems very likely.)

更新:实际上,我真的在寻找耶稣受难日(复活节前的星期五)的日期...我只是以为复活节会把我带到那里.既然我在美国,我想我正在寻找天主教复活节?但如果我错了,也许有人可以纠正我.

UPDATE: Actually, I'm really looking for the date of Good Friday (the Friday before Easter)... I just figured Easter would get me there. And since I'm in the U.S., I assume I'm looking for the Catholic Easter? But perhaps someone can correct me on that if I'm wrong.

*我所说的疯狂"是指,参与.没有任何冒犯...

*By "crazy" I meant, like, involved. Not anything offensive...

推荐答案

在 SQL Server 中,复活节星期天看起来像这样,向下滚动到耶稣受难日

in SQL Server Easter Sunday would look like this, scroll down for Good Friday

CREATE FUNCTION dbo.GetEasterSunday 
( @Y INT ) 
RETURNS SMALLDATETIME 
AS 
BEGIN 
    DECLARE     @EpactCalc INT,  
        @PaschalDaysCalc INT, 
        @NumOfDaysToSunday INT, 
        @EasterMonth INT, 
        @EasterDay INT 

    SET @EpactCalc = (24 + 19 * (@Y % 19)) % 30 
    SET @PaschalDaysCalc = @EpactCalc - (@EpactCalc / 28) 
    SET @NumOfDaysToSunday = @PaschalDaysCalc - ( 
        (@Y + @Y / 4 + @PaschalDaysCalc - 13) % 7 
    ) 

    SET @EasterMonth = 3 + (@NumOfDaysToSunday + 40) / 44 

    SET @EasterDay = @NumOfDaysToSunday + 28 - ( 
        31 * (@EasterMonth / 4) 
    ) 

    RETURN 
    ( 
        SELECT CONVERT 
        (  SMALLDATETIME, 
                 RTRIM(@Y)  
            + RIGHT('0'+RTRIM(@EasterMonth), 2)  
            + RIGHT('0'+RTRIM(@EasterDay), 2)  
        ) 
    ) 

END 
GO

耶稣受难日是这样的,它使用了上面的复活节功能

Good Friday is like this and it uses the Easter function above

CREATE FUNCTION dbo.GetGoodFriday 
( 
    @Y INT 
) 
RETURNS SMALLDATETIME 
AS 
BEGIN 
    RETURN (SELECT dbo.GetEasterSunday(@Y) - 2) 
END 
GO

从这里:http://web.archive.org/web/20070611150639/http://sqlserver2000.databases.aspfaq.com/why-should-i-consider-using-an-auxiliary-calendar-table.html

这篇关于返回给定年份复活节日期的函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆