Is there a way to get the day of the week when supplied with a date? Like November 11, 1911 may be a Monday?

Recommended Answers

All 2 Replies

Python does make it look simple ...

# day of the week of a given date
# date.weekday() returns 0 for Monday and so on, so pick the string from a list

from datetime import date

oldDate = date(1911, 11, 11)  # year, month, day

dayofWeek = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday']
print "The day of the week on %s was a %s" % (oldDate.strftime("%d%b%Y"), dayofWeek[date.weekday(oldDate)])
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.