2001-10-18 I want to calculate weekday e.g. Monday, Tuesday from the date given above. is it possible in python?
Asked
Active
Viewed 2.4k times
5
-
yes it's possible, did you try something ? – Dadep May 19 '17 at 12:20
-
did you try searching for already existing questions? – Norbert Forgacs May 19 '17 at 12:20
-
http://stackoverflow.com/questions/9847213/which-day-of-week-given-a-date-python check this one out – Norbert Forgacs May 19 '17 at 12:20
-
3Possible duplicate of [which day of week given a date python](http://stackoverflow.com/questions/9847213/which-day-of-week-given-a-date-python) – gonczor May 19 '17 at 12:20
2 Answers
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.
ChaimG
- 5,936
- 4
- 30
- 45
Alix Eisenhardt
- 313
- 2
- 10