Click here to Skip to main content
6,932,810 members and growing! (15,495 online)
Email Password   helpLost your password?
General Programming » Date and Time » Algorithms     Intermediate

Calculating Easter Sunday

By Oskar Wieland

How to find Easter Sunday and Ash Wednesday
VC6Win2K, MFC, Dev
Posted:23 Nov 2001
Views:61,714
Bookmarked:13 times
printPrint Friendly   add Share
      Discuss Discuss   Broken Article?Report  
6 votes for this article.
Popularity: 2.00 Rating: 2.57 out of 5
2 votes, 66.7%
1

2

3
1 vote, 33.3%
4

5

Introduction

Looking through old Pascal sources I found an algorithm to calculate Easter Sunday. I reinterpreted it to C++ and packed it into a small MFC dialog application.

The sample calculates Easter from 1970 to 2037. Responsible for the limitation is the function mktime, used to calculate the offset to ash. Basically GetEasterSunday is able to calculate Easter from 1583 (beginning of Gregorian calendar) to 2499 (end of correction values).

Ash Wednesday is 46 days before Easter Sunday.

void
CEasterDlg::GetEasterSunday( WORD wYear, WORD& wMonth, WORD& wDay )
{
    // calculate easter sunday

    // [in]  wYear  - 4-digit year to calculate (but not before 1583)

    // [out] wMonth - month of easter sunday

    // [out] wDay   - day of easter sunday


    WORD wCorrection = 0;   
    
    if( wYear < 1700 )      wCorrection = 4;
    else if( wYear < 1800 ) wCorrection = 5;
    else if( wYear < 1900 ) wCorrection = 6;
    else if( wYear < 2100 ) wCorrection = 0;
    else if( wYear < 2200 ) wCorrection = 1;
    else if( wYear < 2300 ) wCorrection = 2;
    else if( wYear < 2500 ) wCorrection = 3;

    wDay = (19 * (wYear % 19) + 24) % 30;        
    wDay = 22 + wDay + ((2 * (wYear % 4) + 4 * (wYear % 7) + 6 * wDay + 5 + wCorrection) % 7);
    
    // jump to next month

    if( wDay > 31 )
    {
        wMonth = 4;
        wDay -= 31;
    }
    else
    {
        wMonth = 3;
    }
}

Further reading:

http://aa.usno.navy.mil/data/docs/easter.html JavaScript that computes easter sunday.
http://www.hourworld.com/easter.htm More algorithms how to calculate.

Have fun.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

Oskar Wieland


Member

Occupation: Web Developer
Location: Germany Germany

Other popular Date and Time articles:

Article Top
 
You must Sign In to use this message board.
FAQ FAQ 
 
Noise Tolerance  Layout  Per page   
 Msgs 1 to 7 of 7 (Total in Forum: 7) (Refresh)FirstPrevNext
GeneralThe algorithm is incorrect PinmemberSire4045:42 22 Mar '05  
It gives the wrong date for a handful of years between 1583 and 2005, for example 1981.

Try this alrorithm[^] (c++) instead.



--------------------
No one is perfect.
Welll, there was this guy... but we killed him.

GeneralThere are better algorithms. PinmemberWillzyba4:22 22 Nov '04  
GeneralIt does not take into account all the Christians PinmemberAlexandru Savescu13:39 27 Nov '01  
GeneralJust what I was looking for! PinmemberMatt Gullett10:09 26 Nov '01  
GeneralDead link? Pinmemberedx7:30 26 Nov '01  
Generalheheh PinmemberRui Lopes1:56 25 Nov '01  
Generalunusual :-) PinmemberNish [BusterBoy]21:09 24 Nov '01  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+PgUp/PgDown to switch pages.

PermaLink | Privacy | Terms of Use
Last Updated: 23 Nov 2001
Editor: Chris Maunder
Copyright 2001 by Oskar Wieland
Everything else Copyright © CodeProject, 1999-2010
Web09 | Advertise on the Code Project