phone: (540)338-0194
email: ken@kenhamady.com

´╗┐

 Crystal Reports formula examples

How to find Good Friday (or Easter) for any year:

Most holidays are easy to determine in advance because they always occur on a fixed date or they occur in a specific week of a month, like Thanksgiving USA.  The real challenge is Good Friday - the Friday before Easter Sunday.  Because the date of Easter is based on a Lunar calculation it isn't as simple to calculate.  Mike found an algorhythm for calculating Easter and used it in a Crystal formula to determine the date of Good Friday.  This Good Friday formula can, in turn, be referenced in the formula for creating a list of common holidays.  Mikes original formula has full historical comments that some of you might find interesting.  The formula below only shows the authoriship comments.  Both should give the exact same result.  The only input required by this formula are a 4 digit numeric year labled {@yr}


    // Written 6/28/03 by Mike Cook
    // The following calculation of the Date for Easter is based on Oudin's algorithm for
    // determining the date of Easter and follows the algorithm given in the New Scientist
    // magazine, issue No. 228 (Vol. 9) page 828 (March 1961). It was originally coded in 
    // Multics PL/1 by Dennis Capps in 9/80 to fix bug a in the easter calculation in a
    // program called calendar originally written by Tom Van Vleck of MIT in 1972.  It was
    // converted to Crystal and modified to return the date of Good Friday by Mike Cook in
    // 2003.  The comments are mostly from the original PL/1.It should be valid for any date
    // from 1583 to 4099, so we may have a year 4K issue.

    Local numberVar yr := {@yr};  // The year for which to determine the date of Good Friday.
    Local numberVar a := yr Mod 19;     
    Local numberVar b := yr \ 100;    
    Local numberVar c := yr Mod 100;  
    Local numberVar d := b \ 4;
    Local numberVar e := b Mod 4;     
    Local numberVar i := c \ 4;
    Local numberVar k := c Mod 4;
    Local numberVar g := (8 * b + 13) \ 25;
    Local numberVar h := ((19 * a) + b - d - g + 15) Mod 30;
    Local numberVar l := ((2 * e) + (2 * i) - k + 32 - h) Mod 7;
    Local numberVar m := (a + (11*h) + (19*l)) \ 433;
    Local numberVar days_to_good_friday := h + l - (7*m) - 2; 
    Local numberVar mo := (days_to_good_friday + 90) \ 25;
    Local numberVar da := (days_to_good_friday + (33 * mo) + 19) Mod 32;
    cdate ( yr, mo, da)     // Returns the date of Good Friday