Q:

Find the day of the week of a given date using python programming

belongs to collection: Python Date and Time Exercises

0

Find the day of the week of a given date

Given:

given_date = datetime(2020, 7, 26)

Expected output:

Sunday

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Solution1:

from datetime import datetime

given_date = datetime(2020, 7, 26)

# to get weekday as integer
print(given_date.today().weekday())

# To get the english name of the weekday
print(given_date.strftime('%A'))

Solution2:using calendar module

import calendar
from datetime import datetime

given_date = datetime(2020, 7, 26)
weekday = calendar.day_name[given_date.weekday()]
print(weekday)

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Add a week (7 days) and 12 hours to a given date u... >>
<< Print a date in a the following format using pytho...