Determine easter for a given year

ddanbe 2 Tallied Votes 986 Views Share

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);
	}
tomtheman5 0 Newbie Poster

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

ddanbe 2,724 Professional Procrastinator Featured Poster

Glad to help you.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.