Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I calculate what date Good Friday falls on, given a year?

Does anyone have a good algorithm to calculate what date Good Friday falls on given the year as an input? Preferably in C#.

like image 321
Bryan Denny Avatar asked Mar 24 '10 18:03

Bryan Denny


2 Answers

Here's a great article that should help you build your algorithm

http://www.codeproject.com/KB/datetime/christianholidays.aspx

Based on this example, you should be able to write:

DateTime goodFriday = EasterSunday(DateTime.Now.Year).AddDays(-2); 

Full Example:

public static DateTime EasterSunday(int year) {     int day = 0;     int month = 0;      int g = year % 19;     int c = year / 100;     int h = (c - (int)(c / 4) - (int)((8 * c + 13) / 25) + 19 * g + 15) % 30;     int i = h - (int)(h / 28) * (1 - (int)(h / 28) * (int)(29 / (h + 1)) * (int)((21 - g) / 11));      day   = i - ((year + (int)(year / 4) + i + 2 - c + (int)(c / 4)) % 7) + 28;     month = 3;      if (day > 31)     {         month++;         day -= 31;     }      return new DateTime(year, month, day); } 
like image 136
hunter Avatar answered Oct 07 '22 17:10

hunter


Don't Repeat Yourself

Think

Realize that calculating Easter is what you are really dependent upon.

Research

Here is the offical Naval Observatory page for calculating Easter.

http://aa.usno.navy.mil/faq/docs/easter.php

Execute

Use the formula for calculating Easter then shift to the previous Friday (or subtract 2 days, details up to you).

like image 30
Kelly S. French Avatar answered Oct 07 '22 17:10

Kelly S. French