How-to: Calculate the date of Easter with a function.

The Pascha function below will calculate the date of Easter Sunday. The DemoEaster function calls Pascha() passing a range of years, it will work for years far into the future (millions of years.)

[Start Easter.vbs]

DemoEaster 1550, 2100

Sub DemoEaster (Y1, Y2)
Dim Y, M, D
for Y = Y1 to Y2
  Pascha Y, M, D
  Wscript.echo St, Y & "-0" & M & "-" & LdgZ(D)
Next
End sub
 
Function LdgZ(ByVal N)
  if (N>=0) and (N<10) then LdgZ = "0" & N else LdgZ = "" & N
End function

Sub Pascha(iYear, iMonth, iDay)
 'Reads Year
 'Returns the Month and Day of Easter Sunday.
  Dim C, G, K, I, J, L
 
  G = iYear mod 19
 
  if iYear > 1582 then
    C = iYear \ 100
    K = (C - 17) \ 25
    I = C - (C \ 4) - ((C - K) \ 3) + 19 * G + 15
    I = I mod 30
    I = I - (I \ 28) * (1 - (I \ 28) * (29 \ (I + 1)) * ((21 - G) \ 11))
    J = iYear + (iYear \ 4) + I + 2 - C + (C \ 4)
    J = J mod 7
  else
    I = ((19 * G) + 15) mod 30
    J = (iYear + (iYear \ 4) + I) mod 7
  end if
 
  L = I - J
  iMonth = 3 + ((L + 40) \ 44)
  iDay = L + 28 - 31 * (iMonth \ 4)

End sub

[End Easter.vbs]

The Pascha function above gives a Julian date for Easter in years before 1583 otherwise it returns a standard Gregorian date.

Source: Newsgroups (May 2003) > Dr J.R. Stockton’s website. The Pascha function is based on the algorithm of Oudin (1940) a recognised algorithm for computing the date of Easter, it can be considered to be in the public domain.

This is the Western/Christian definition of Easter, many other methods exist for calculating Easter, "algorithm of Oudin" is a useful Google search to find other Easter algorithms and programming functions.

Examples

cscript easter.vbs

“Gather ye rosebuds while ye may, Old Time is still a flying; And that same flower that blooms today, Tomorrow shall be dying” ~ Fredrick O' R. Hayes

Related VBScript commands

DateTime - Get Date, Time and daylight savings.
PowerShell: Calculate the date of Easter.


 
Copyright © 1999-2024 SS64.com
Some rights reserved