Python Forum
Date format error getting weekday value - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Date format error getting weekday value (/thread-37341.html)



Date format error getting weekday value - Aggie64 - May-29-2022

I get the following error on line 4 when running the code below:
valueError: timedata '05/09/2022' does not match format '%m %d %Y'

I am trying to get a weekday value from 0-6 from a date represented in a string.

1 #!/usr/bin/env python3
2 import datetime
3 strdate = "05/29/2022"
4 day=datetime.datetime.strptime(strdate, "%m %d %Y").weekday()
5 print("weekday = ",day)


RE: Date format error getting weekday value - Axel_Erfurt - May-29-2022

You have

'05/09/2022'

the you should use

"%m/%d/%Y"


RE: Date format error getting weekday value - Aggie64 - May-29-2022

(May-29-2022, 06:56 PM)Axel_Erfurt Wrote: You have

'05/09/2022'

the you should use

"%m/%d/%Y"

Thank you very very much, your reply fixed the problem!!!