944,082 Members | Top Members by Rank

Ad:
  • Python Discussion Thread
  • Marked Solved
  • Views: 14856
  • Python RSS
Aug 1st, 2005
0

Day of Week

Expand Post »
Is there a way to get the day of the week when supplied with a date? Like November 11, 1911 may be a Monday?
Similar Threads
Reputation Points: 404
Solved Threads: 180
Nearly a Posting Virtuoso
bumsfeld is offline Offline
1,422 posts
since Jul 2005
Aug 1st, 2005
0

Re: Day of Week

you might find some good info here
http://www.daniweb.com/techtalkforum...ad20774-2.html
Reputation Points: 10
Solved Threads: 17
Posting Whiz in Training
shanenin is offline Offline
217 posts
since May 2005
Aug 1st, 2005
0

Re: Day of Week

Python does make it look simple ...
python Syntax (Toggle Plain Text)
  1. # day of the week of a given date
  2. # date.weekday() returns 0 for Monday and so on, so pick the string from a list
  3.  
  4. from datetime import date
  5.  
  6. oldDate = date(1911, 11, 11) # year, month, day
  7.  
  8. dayofWeek = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday']
  9. print "The day of the week on %s was a %s" % (oldDate.strftime("%d%b%Y"), dayofWeek[date.weekday(oldDate)])
Last edited by vegaseat; Sep 23rd, 2008 at 11:53 pm. Reason: replace disfunctional php tags
Moderator
Reputation Points: 1333
Solved Threads: 1403
DaniWeb's Hypocrite
vegaseat is offline Offline
5,792 posts
since Oct 2004

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Python Forum Timeline: mandelbrot generator messed up
Next Thread in Python Forum Timeline: help me understand what is happening





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC