Ever wondered how to calculate the date of easter?
Well here is how to do it in C#

``````public DateTime EasterDate(int Year)
{
// Gauss Calculation
////////////////////

int Month = 3;

// Determine the Golden number:
int G = Year % 19 + 1;

// Determine the century number:
int C = Year / 100 + 1;

// Correct for the years who are not leap years:
int X = ( 3 * C ) / 4 - 12;

// Mooncorrection:
int Y = ( 8 * C + 5 ) / 25 - 5;

// Find sunday:
int Z = ( 5 * Year ) / 4 - X - 10;

// Determine epact(age of moon on 1 januari of that year(follows a cycle of 19 years):
int E = ( 11 * G + 20 + Y - X ) % 30;
if (E == 24) {E++;}
if ((E == 25) && (G > 11)) {E++;}

// Get the full moon:
int N = 44 - E;
if (N < 21) {N = N + 30;}

// Up to sunday:
int P = ( N + 7 ) - ( ( Z + N ) % 7 );

// Easterdate:
if ( P > 31 )
{
P = P - 31;
Month = 4;
}
return new DateTime(Year, Month, P);
}``````
2
Contributors
2
Replies
16
Views
9 Years
Discussion Span
Last Post by ddanbe

Hey, just want to say thanks for putting the Gauss calculation into C#. Trying to calculate different holidays, and this helped a lot!