5

2001-10-18 I want to calculate weekday e.g. Monday, Tuesday from the date given above. is it possible in python?

Ali Hamza
  • 111
  • 1
  • 1
  • 5

2 Answers2

10

Here is one way to do this:

dt = '2001-10-18'
year, month, day = (int(x) for x in dt.split('-'))    
answer = datetime.date(year, month, day).weekday()
Amit Wolfenfeld
  • 513
  • 5
  • 9
6

There is the weekday() and isoweekday() methods for datetime objects.

Python doc

ChaimG
  • 5,936
  • 4
  • 30
  • 45
Alix Eisenhardt
  • 313
  • 2
  • 10