Click here to Skip to main content
12,950,084 members (44,842 online)
Click here to Skip to main content
Add your own
alternative version

Stats

81.2K views
479 downloads
15 bookmarked
Posted 23 Nov 2001

Calculating Easter Sunday

, 23 Nov 2001
Rate this:
Please Sign up or sign in to vote.
How to find Easter Sunday and Ash Wednesday
<!-- Download Links --> <!-- Main HTML starts here -->

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

Share

About the Author

Oskar Wieland
Web Developer
Germany Germany
No Biography provided

You may also be interested in...

Comments and Discussions

 
GeneralThe algorithm is incorrect Pin
Sire40422-Mar-05 4:42
memberSire40422-Mar-05 4:42 
GeneralThere are better algorithms. Pin
Willzyba22-Nov-04 3:22
memberWillzyba22-Nov-04 3:22 
GeneralIt does not take into account all the Christians Pin
Alexandru Savescu27-Nov-01 12:39
memberAlexandru Savescu27-Nov-01 12:39 
GeneralJust what I was looking for! Pin
Matt Gullett26-Nov-01 9:09
memberMatt Gullett26-Nov-01 9:09 
QuestionDead link? Pin
edx26-Nov-01 6:30
memberedx26-Nov-01 6:30 
Generalheheh Pin
Rui Lopes25-Nov-01 0:56
memberRui Lopes25-Nov-01 0:56 
Generalunusual :-) Pin
Nish [BusterBoy]24-Nov-01 20:09
memberNish [BusterBoy]24-Nov-01 20:09 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

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

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170525.1 | Last Updated 24 Nov 2001
Article Copyright 2001 by Oskar Wieland
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid