Results 1 to 4 of 4

Thread: Do you know when Easter is this year?

  1. #1
    Forum Guru Rick Rothstein's Avatar
    Join Date
    Feb 2012
    Posts
    659
    Rep Power
    13

    Do you know when Easter is this year?

    Let me start by saying the code below is old, quite old for that matter. Back in the early 1980's, I came across a written algorithm for how to calculate when Easter falls for any given year. It was a word description for a series of calculations that would end up with the month and day for the given year that Easter falls on. So I decided back then to encode it into BASIC (the predecessor to VB). There were memory limitations back then, so the style was to use very short variable names (actually, there may have been a 2 significant character limit back then if I am remembering correctly). Being that so many years have passed, and the fact I have not seen the article the code was derived from for possibly 30 years now, the code still retains the one-character variable names I used originally.

    This function can be called either from your own VB code or used as a UDF (user defined function) directly inside a worksheet formula. When called from VB code, the minimum year value that can be passed in for its argument is 1583... has to do with when the Gregorian Calendar was first adopted, but know that 1583 was not the adoption date everywhere in the world, so if you plan to call this function with really early dates, you should verify the adoption date for the Gregorian Calendar in the locale you plan to use the function at. When called as a UDF, the function will correctly handle the 1904 date system if that is in-use on the computer the formula is calculate on (this is an addition to the code I was able to implement awhile ago) and the minimum year argument is 1900 for the standard date system and 1904 for the 1904 date system. Oh, I almost forgot, the maximum year argument for either date system is 9999.

    Code:
    Function Easter(ByVal YearIn As Integer) As Date
    
        Dim a As Long, b As Long, c As Long, d As Long, e As Long, f As Long, g As Long
        Dim h As Long, i As Long, k As Long, l As Long, m As Long, n As Long, p As Long
        Dim Adjustment1904 As Long
        
        If ActiveWorkbook.Date1904 Then Adjustment1904 = 1462
        
        If TypeName(Application.Caller) = "Range" Then
            If YearIn < 1900 - 4 * ActiveWorkbook.Date1904 Then
                Easter = CVErr(xlErrValue)
                Exit Function
            End If
        ElseIf YearIn < 1583 Then
            Err.Raise 5
        End If
    
        a = YearIn Mod 19
        b = YearIn \ 100
        c = YearIn Mod 100
        d = b \ 4
        e = b Mod 4
        f = (b + 8) \ 25
        g = (b - f + 1) \ 3
        h = (19 * a + b - d - g + 15) Mod 30
        i = c \ 4
        k = c Mod 4
        l = (32 + 2 * e + 2 * i - h - k) Mod 7
        m = (a + 11 * h + 22 * l) \ 451
        n = (h + l - 7 * m + 114) \ 31
        p = (h + l - 7 * m + 114) Mod 31
        
        Easter = DateSerial(YearIn, n, p + 1) - Adjustment1904
    
    End Function

  2. #2
    Administrator Admin's Avatar
    Join Date
    Mar 2011
    Posts
    1,122
    Rep Power
    10
    I found a shorter formula here

    =DOLLAR(("4/"&A1)/7+MOD(19*MOD(A1,19)-7,30)*14%,)*7-6

    but it gives, incorrect results after year 2203

    Also see The Date of Easter
    Cheers !

    Excel Range to BBCode Table
    Use Social Networking Tools If You Like the Answers !

    Message to Cross Posters

    @ Home - Office 2010/2013/2016 on Win 10 (64 bit); @ Work - Office 2016 on Win 10 (64 bit)

  3. #3
    Forum Guru Rick Rothstein's Avatar
    Join Date
    Feb 2012
    Posts
    659
    Rep Power
    13
    Quote Originally Posted by Admin View Post
    I found a shorter formula here

    =DOLLAR(("4/"&A1)/7+MOD(19*MOD(A1,19)-7,30)*14%,)*7-6

    but it gives, incorrect results after year 2203
    The DOLLAR function? 14%? Really? How do people manage to figure these things out (even with the year 2203 restriction)???

    Quote Originally Posted by Admin View Post
    Interesting... the algorithm in the article you cited is completely different from the underlying algorithm behind the code I posted, yet they both produce identical results. To be sure they produced identical results, I created a UDF from the article's "code" (inserting Int function calls where necessary) and compared results from my posted function and the new UDF for the years 1583 to 9999 and they both produced the same Easter date for each year.

  4. #4
    Junior Member
    Join Date
    Jul 2021
    Posts
    6
    Rep Power
    0
    Hi Rick,
    While browsing your ”corner”, the “Do you know when Easter is this year?” post (page 3) caught my attention. Back in the nineties I was “playing” with a “perpetual” calendar, first in Lotus Symphony and then in Excel. I wanted to highlight the day of Easter and I found the Gauss algorithm on the Internet which was, I remember, exactly the same as the one you used in your post. You preserved the original but I found it quite lengthy and noticed that many variables were only used once. So, I integrated the code of these variables directly where they were used. I also noticed that the two penultimate lines of code (n and p) are identical except for the last operation ( \ 31 and Mod 31). So, I moved these to the final code line, where they are referenced, and kept only one line of those two. Here is my very compacted version:

    Code:
    Function Easter(Y As Integer) As Date
    Dim a As Integer, b As Integer, c As Integer, d As Integer, e As Integer
       a = Y Mod 19
       b = Y \ 100
       c = Y Mod 100
       d = (19 * a + b - b \ 4 - (b - (b + 8) \ 25 + 1) \ 3 + 15) Mod 30
       e = (32 + 2 * (b Mod 4) + 2 * (c \ 4) - d - (c Mod 4)) Mod 7
       e = d + e - 7 * ((a + 11 * d + 22 * e) \ 451) + 114
       Easter = DateSerial(Y, e \ 31, e Mod 31 + 1)
    End Function
    When this version is compared with the original code, it’s hard to believe that they are if fact the same algorithm.

    I neglected the minimum 1900 restriction of Excel and the 1900/1904 option. In 1999 I decided to add a “perpetual calendar” to my website (www.wv-be.com/Kalender.asp). Being an .asp page, the code of the Easter function could be used as is but now, being pure vb script, it could be used, without the Excel restrictions, from 1583 till 9998. I tested both versions for that range and found that the results were identical.

Similar Threads

  1. Test Copy Do you know when Easter is this year?
    By Rick Rothstein in forum Test Area
    Replies: 6
    Last Post: 08-01-2021, 08:23 PM
  2. Do you know when Easter is this year?
    By Rick Rothstein in forum Test Area
    Replies: 3
    Last Post: 08-01-2021, 08:23 PM
  3. Happy New Year
    By mahmoud-lee in forum Excel Help
    Replies: 7
    Last Post: 01-02-2014, 10:08 PM
  4. Happy New Year
    By mahmoud-lee in forum Greetings and Inception
    Replies: 7
    Last Post: 01-02-2014, 10:08 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •