Python Forum
String formatting (strptime) issues - 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: String formatting (strptime) issues (/thread-39126.html)



String formatting (strptime) issues - Henrio - Jan-05-2023

Please help out to review the problems with my code. It threw up an error message which says;
Value Error: time data ')' does not match format '%H:%M:%S'


RE: String formatting (strptime) issues - rob101 - Jan-06-2023

If you look at your screenshot, you'll see that the error relates to line 92 in your code, but we can't see line 92, so how are we to help?

That said, it's already been pointed out that a screenshot is not the way to present this.


RE: String formatting (strptime) issues - deanhystad - Jan-06-2023

Please post code, not screenshots. If there is an error, post the entire error message, including the entire traceback. Make sure to post the code referenced in the error message.

Your error is on line 92 in your program. There is a datetime.strptime(data_string, format) call where the data_str is does not follow the specified format in the "format" variable ("%H:%M:%S"). At a minimum data_str contains a ')' that is not part of the format. There could be more mismatches.

A few comments on the code you did share with us:
from datetime import datetime
from time import time

# do this
now = datetime.now()
dt_str = now.strftime('%Y-%m-%d %H-%M-%S')
filename = f'Attendance/Attendance {dt_str}'

# not this
now = time()
dt = datetime.fromtimestamp(now)
date_str = dt.strftime("%Y-%m-%d")
time_str = dt.strftime("%H:%M:%S")
h, m, s = time_str.split(':')
filename = f'Attendance/Attendance {date_str} {h}-{m}-{s}'