返回给定年份的复活节日期的函数 [英] Function to return date of Easter for the given year
问题描述
所以,这里有一个有趣的小编程挑战。我正在写一个快速方法来确定特定年份的所有市场假日,然后我开始阅读复活节,并发现只是多么疯狂*的逻辑是确定其日期 - 在 Paschal满月之后的第一个星期日后春分!有没有人知道一个现有的函数来计算一个给定年份的复活节日期?
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 :实际上,我真的在寻找 strong>(星期五之前的复活节)...我只是想了复活节会让我在那里。因为我在美国,我想我在寻找天主教复活节?但是如果我错了,也许有人可以纠正我。
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.
*疯狂我的意思, 。没有任何进攻...
推荐答案
在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
strong> Good Friday 就是这样,它使用上面的复活节功能
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
这篇关于返回给定年份的复活节日期的函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!