Python Forum
Printing Easter date occurrences
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Printing Easter date occurrences
#9
Superb, buran! That date(year, m_target, d_target) is what I was looking for at the beginning of my investigations. Thanks again, and cheers

# ---------- pasqua.py ----------
from datetime import date
   
def calc_easter(year):
    "Returns Easter as a date object."
    a = year % 19
    b = year // 100
    c = year % 100
    d = (19 * a + b - b // 4 - ((b - (b + 8) // 25 + 1) // 3) + 15) % 30
    e = (32 + 2 * (b % 4) + 2 * (c // 4) - d - (c % 4)) % 7
    f = d + e - 7 * ((a + 11 * d + 22 * e) // 451) + 114
    month = f // 31
    day = f % 31 + 1    
    return date(year, month, day)
     
# ----- Years interval ---------  
start_interval = 1950
end_interval = 2050
# ----- Wished month/day occurrence ---------
m_target= 4    # 3 or 4
d_target= 21   # 1 to 31
#
for year in range(start_interval, end_interval):
	easter = calc_easter(year=year)
	if easter == date(year, m_target, d_target):	
		print(easter.strftime('%Y-%m-%d'))
#
# --------- OUTPUT ------------
# C:\Training>python pasqua.py
# 1957-04-21
# 2019-04-21
# 2030-04-21
# 2041-04-21
# ------------------------------
Reply


Messages In This Thread
Printing Easter date occurrences - by samsonite - Mar-05-2019, 08:22 AM
RE: Printing Easter date occurrences - by samsonite - Mar-05-2019, 04:38 PM
RE: Printing Easter date occurrences - by woooee - Mar-05-2019, 05:38 PM
RE: Printing Easter date occurrences - by samsonite - Mar-05-2019, 05:54 PM
RE: Printing Easter date occurrences - by samsonite - Mar-06-2019, 06:39 AM
RE: Printing Easter date occurrences - by buran - Mar-06-2019, 07:49 AM
RE: Printing Easter date occurrences - by samsonite - Mar-06-2019, 09:41 AM
RE: Printing Easter date occurrences - by buran - Mar-06-2019, 10:05 AM
RE: Printing Easter date occurrences - by samsonite - Mar-06-2019, 11:49 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Compare current date on calendar with date format file name Fioravanti 1 251 Mar-26-2024, 08:23 AM
Last Post: Pedroski55
  Python date format changes to date & time 1418 4 623 Jan-20-2024, 04:45 AM
Last Post: 1418
  Date format and past date check function Turtle 5 4,281 Oct-22-2021, 09:45 PM
Last Post: deanhystad
  How to add previous date infront of every unique customer id's invoice date ur_enegmatic 1 2,245 Feb-06-2021, 10:48 PM
Last Post: eddywinch82
  Count number of occurrences of list items in list of tuples t4keheart 1 2,398 Nov-03-2020, 05:37 AM
Last Post: deanhystad
  Count & Sort occurrences of text in a file oradba4u 7 3,097 Sep-06-2020, 03:23 PM
Last Post: oradba4u
  How to add date and years(integer) to get a date NG0824 4 2,892 Sep-03-2020, 02:25 PM
Last Post: NG0824
  Counting number of occurrences of a single digit in a list python_newbie09 12 5,565 Aug-12-2019, 01:31 PM
Last Post: perfringo
  Occurrences using FOR and IF cycle P86 2 2,532 Jul-29-2019, 04:37 PM
Last Post: ThomasL
  Substracting today's date from a date in column of dates to get an integer value firebird 1 2,137 Jul-04-2019, 06:54 PM
Last Post: Axel_Erfurt

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020