Python Forum
Christmas and other occasions - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Christmas and other occasions (/thread-19811.html)



Christmas and other occasions - GalaxyCoyote - Jul-15-2019

I am trying to make a program that can tell people the date and time (I have done this bit) but I want to add to the program, I want a way to detect the date and then display a little message depending on the date.

e.g.

#if date == 25/12
#print("Merry christmas!")
and

#if date == 1/1
#print("Happy new year!")
etc.
etc.


RE: Christmas and other occasions - Yoriz - Jul-15-2019

import datetime

today = datetime.date.today()

if (today.day, today.month) == (15, 7):
    print('today is 15th day and 7th month')
else:
    print('you have run this code on a different day')
Output:
today is 15th day and 7th month



RE: Christmas and other occasions - GalaxyCoyote - Jul-15-2019

(Jul-15-2019, 08:19 PM)Yoriz Wrote:
import datetime

today = datetime.date.today()

if (today.day, today.month) == (15, 7):
    print('today is 15th day and 7th month')
else:
    print('you have run this code on a different day')
Output:
today is 15th day and 7th month

Ok then thanks!


RE: Christmas and other occasions - nilamo - Jul-15-2019

Holidays are complicated. I'd recommend just using a list someone else made, such as this one: https://github.com/dr-prodigy/python-holidays


RE: Christmas and other occasions - GalaxyCoyote - Jul-18-2019

(Jul-15-2019, 09:13 PM)nilamo Wrote: Holidays are complicated. I'd recommend just using a list someone else made, such as this one: https://github.com/dr-prodigy/python-holidays

I am only trying to implement set holidays, (Christmas lands on the 25th every year)