Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Calculating the date of Easter

Usefull Functions & Procedures

Calculating the date of Easter

by  Mike Lewis  Posted    (Edited  )
In the modern Gregorian calendar, Easter Day is 'the first Sunday after the first full moon on or after the vernal equinox'. At first glance, it seems impossible to calculate that date programmatically. However, the following VFP function will do the job.

Code:
FUNCTION Easter
* Calculates the date of Easter for a given year. 
* Accepts years in the range 100 to 9999. However, 
* for years before the adoption of the Gregorian
* Calendar (1582 - 1587 in much of Europe, 1752 in 
* Britain and North America) the calculation 
* is inappropriate.

LPARAMETERS tnYear

IF EMPTY(tnYear) OR NOT BETWEEN(tnYear,100,9999)
  ERROR "Invalid year for Easter calculation"
ENDIF 

LOCAL lnCentury, lnG, lnI, lnK, lnJ, lnL
LOCAL lnEasterDay, lnEasterMonth

lnCentury = INT(tnYear/100)
lnG = MOD(tnYear, 19)
lnK = INT((lnCentury - 17)/25)
lnI = MOD((lnCentury - INT(lnCentury/4) - ;
  INT((lnCentury - lnK)/3) + 19*lnG + 15), 30)
lnI = lnI - INT(lnI/28) * ((1 - INT(lnI/28) * ;
  (INT(29/(lnI+1)) * (INT((21-lnG)/11)))))
lnJ = MOD((tnYear + INT(tnYear/4) + lnI + 2 - ; 
  lnCentury + INT(lnCentury/4)), 7)
lnL = lnI - lnJ
lnEasterMonth = 3 + INT((lnL + 40)/44)
lnEasterDay = lnL + 28 - 31*INT(lnEasterMonth/4)

RETURN DATE(tnYear,lnEasterMonth,lnEasterDay)

ENDFUNC

Mike Lewis
Edinburgh, Scotland
www.ml-consult.co.uk
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top