Python ProgrammingPython Programming

Get the day of week from given a date in Python

A short program to get the day of week from given a date in Python using weekday and isoweekday.
##
# Python's program to get the day of week of today or given date.

import datetime

dayofweek = datetime.date(2010, 6, 16).strftime("%A")
print(dayofweek)
# weekday Monday is 0 and Sunday is 6
print("weekday():", datetime.date(2010, 6, 16).weekday())

# isoweekday() Monday is 1 and Sunday is 7
print("isoweekday()", datetime.date(2010, 6, 16).isoweekday())

dayofweek = datetime.datetime.today().strftime("%A")
print(dayofweek)
print("weekday():", datetime.datetime.today().weekday())
print("isoweekday()", datetime.datetime.today().isoweekday())

Sample output of above program.
C:\programs\time>pep8 --first example7.py

C:\programs\time>python example7.py
Wednesday
weekday(): 2
isoweekday() 3
Friday
weekday(): 4
isoweekday() 5

C:\programs\time>