954,557 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Day of Week

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

bumsfeld
Nearly a Posting Virtuoso
1,445 posts since Jul 2005
Reputation Points: 404
Solved Threads: 184
 
shanenin
Posting Whiz in Training
217 posts since May 2005
Reputation Points: 10
Solved Threads: 17
 

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)])
vegaseat
DaniWeb's Hypocrite
Moderator
5,989 posts since Oct 2004
Reputation Points: 1,345
Solved Threads: 1,417
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You