## A Conversation for Calculating the Date of Easter

### MS Office Macro

Geoff Taylor - Gullible Chump Started conversation Dec 21, 2001

Based entirely on Gnomon's work, you can cut & paste the following into an MS Excel macro module as a functioning macro...

Sub Easter()

' Courtesy of GNOMON, A H2G2 Researcher - Dec 2001

' http://www.bbc.co.uk/h2g2/guide/A653267

' Given the Year as a four digit number in the range 1700 - 2299

' Calculate Day and Month of Easter Sunday

' Note 1: the algorithm has not been tested outside this range.

' Note 2: the \ operator performs integer division without remainder.

' Note 3: the date returned is the Gregorian Calendar date

' (the one we use now), even for dates in the 18th Century.

Dim a, b, c, d, e, f, g, h, i, j, k, m, n, Month, Day

Dim Year

Year = InputBox("Enter the Year (yyyy) and the date of Easter Sunday will be calculated")

a = Year Mod 19

b = Year \ 100

c = Year Mod 100

d = b \ 4

e = b Mod 4

f = c \ 4

g = c Mod 4

h = (b + 8 ) \ 25

i = (b - h + 1) \ 3

j = (19 * a + b - d - i + 15) Mod 30

k = (32 + 2 * e + 2 * f - j - g) Mod 7

m = (a + 11 * j + 22 * k) \ 451

n = j + k - 7 * m + 114

Month = n \ 31

Day = (n Mod 31) + 1

MsgBox ("Day " & Day & " of Month " & Month)

End Sub

I hope this is useful to someone.. it is to me.

Thanks GNOMON

Geoff Taylor

### MS Office Macro

Geoff Taylor - Gullible Chump Posted Dec 21, 2001

Argh... Smiley alert!!!

I cut and pasted my code into my entry, and H2G2 decided to recognise the bigeyes smiley. When you paste this into Excel, the smiley will be ignored. You will need to manually type an "8" and an ")" in its place.

I'll contact TPTB and see if they can kill the smiley, but until then....

### MS Office Macro

Gnomon - time to move on Posted Dec 21, 2001

You could just put a space between the 8 and the ).

### MS Office Macro

Lakeman Posted Mar 31, 2003

I got bored and thought I'd mess around with the macro.

Thanks Gnomon and Geoff Taylor has left the building.

Sub Easter version2()

' Courtesy of GNOMON, A H2G2 Researcher - Dec 2001

' http://www.bbc.co.uk/h2g2/guide/A653267

' http://www.bbc.co.uk/h2g2/alabaster/U185857

' Given the Year as a four digit number in the range 1700 - 2299

' Calculate Day and Month of Easter Sunday

' Note 1: the algorithm has not been tested outside this range.

' Note 2: the \ operator performs integer division without remainder.

' Note 3: the date returned is the Gregorian Calendar date

' (the one we use now), even for dates in the 18th Century.

Dim a, b, c, d, e, f, g, h, i, j, k, m, n, Month, Month1, Day, Suffix, TodaysDate, DateInQuestion

Dim Year

Year = InputBox("Enter the Year (yyyy) and the date of Easter Sunday will be calculated")

If Year < 1700 Then GoTo Line3

If Year > 2299 Then GoTo Line2 Else GoTo Line1

Line1:

a = Year Mod 19

b = Year \ 100

c = Year Mod 100

d = b \ 4

e = b Mod 4

f = c \ 4

g = c Mod 4

h = (b + 8) \ 25

i = (b - h + 1) \ 3

j = (19 * a + b - d - i + 15) Mod 30

k = (32 + 2 * e + 2 * f - j - g) Mod 7

m = (a + 11 * j + 22 * k) \ 451

n = j + k - 7 * m + 114

Month = n \ 31

Day = (n Mod 31) + 1

If Month = 3 Then Month1 = "March"

If Month = 4 Then Month1 = "April"

Suffix = "th" 'initialise variable

If Day = 1 Then Suffix = "st"

If Day = 21 Then Suffix = "st"

If Day = 31 Then Suffix = "st"

If Day = 2 Then Suffix = "nd"

If Day = 22 Then Suffix = "nd"

If Day = 3 Then Suffix = "rd"

If Day = 23 Then Suffix = "rd"

If Year < 2003 Then GoTo LineA Else GoTo LineB 'for dates in the past or future

LineA:

MsgBox ("Easter Sunday in " & Year & " was on the " & Day & Suffix & " of " & Month1)

GoTo LineC 'dates in the past

If Year > 2003 Then GoTo LineB

LineB:

MsgBox ("Easter Sunday in " & Year & " will be on the " & Day & Suffix & " of " & Month1)

GoTo LineC 'dates in the future

LineC:

MsgBox ("Thanks for taking an interest in Christianity. For more information visit your local church.")

GoTo Line4

Line2:

MsgBox ("Sorry, the year cannot be after 2299")

GoTo Line4

Line3:

MsgBox ("Sorry, the year cannot be before 1700")

Line4:

End Sub

### MS Office Macro

Geoff Taylor - Gullible Chump Posted Apr 1, 2003

Sssh... I'm making a principled stand at the moment and I'm not supposed to be posting to H2G2, but...

I like the added bells and whistles, and line C is a hoot. However, you've hard-coded 2003 into your calculation. You can get the current year like this...

dim Thisyear

Thisyear = year(now)

If I'm telling granny to suck eggs then please ignore me!

Geoff

### MS Office Macro

Lakeman Posted Apr 2, 2003

That's great! I thought for ages about how to get the current year, but I couldn't figure it out. It was getting all complicated using dd/mm/yyyy and I decided to give up. Thanks.

Key: Complain about this post

### MS Office Macro

- 1: Geoff Taylor - Gullible Chump (Dec 21, 2001)
- 2: Geoff Taylor - Gullible Chump (Dec 21, 2001)
- 3: Gnomon - time to move on (Dec 21, 2001)
- 4: Geoff Taylor - Gullible Chump (Dec 21, 2001)
- 5: Peta (Dec 21, 2001)
- 6: Lakeman (Mar 31, 2003)
- 7: Gnomon - time to move on (Mar 31, 2003)
- 8: Geoff Taylor - Gullible Chump (Apr 1, 2003)
- 9: Lakeman (Apr 2, 2003)

### More Conversations for Calculating the Date of Easter

### Write an Entry

"The Hitchhiker's Guide to the Galaxy is a wholly remarkable book. It has been compiled and recompiled many times and under many different editorships. It contains contributions from countless numbers of travellers and researchers."