Reputation: 31
I would like to write a program that gives the day of the week on the 30th of the month. I have a code in which I have to specify the date, what can I change in it to work specifically for the 30th of the month?
import datetime
date=str(input('(Date for example 30 03 2019):'))
day_name= ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday','Sunday']
day = datetime.datetime.strptime(date, '%d %m %Y').weekday()
print(day_name[day])
Upvotes: 1
Views: 53
Reputation: 9504
try this:
from datetime import datetime
year = int(input("Please enter year:"))
month = int(input("Please enter month:"))
try:
print(datetime(year,month,30).strftime("%A"))
except ValueError as ex:
# in February there is no 30 days
print(f"No such date - {year}-{month}-30")
Keep in mind that you have to think about another logic for February...
Upvotes: 1