Please someone should help me to review my code and solve this error;
(Value Error: time data) does not march ‘%Y-%m-%d %H:%M:%S’
Please don’t post screenshots. Post the smallest complete example that shows the problem and wrap it in triple backticks to preserve the formatting, like this:
```python
if True:
print(''Hello world!')
```
Also post the complete traceback so that we know which line is the problem.
Okay thanks. will do that later
elif event == 'Clock OUT':
check = sg.PopupYesNo(' Are you clocking OUT?')
if check == 'Yes':
ts = time.time()
timeStamp = datetime.datetime.fromtimestamp(ts).strftime("%H:%M:%S")
attendance.at[attendance[attendance['Id'] == Id].index.values, 'Clock OUT Time'] = timeStamp
co = attendance.loc[attendance[attendance['Id'] == Id].index.values, 'Clock OUT Time'].to_string().split(' ')
ci = attendance.loc[attendance[attendance['Id'] == Id].index.values, 'Clock IN Time'].to_string().split(' ')
aa = str(aa)[2:-2]
FMT = "%H:%M:%S"
line 92 ==> duration = datetime.datetime.strptime(co[-1], FMT) - datetime.datetime.strptime(ci[-1], FMT)
attendance.at[attendance[attendance['Id'] == Id].index.values, 'Duration'] = duration
d = datetime.datetime.strptime(lecture, FMT) - datetime.datetime.strptime(str(duration), FMT)
if int(str(d).split(':')[1]) in range(-5, 6):
attendance.at[attendance[attendance['Id'] == Id].index.values, 'Status'] = 'Present'
else:
attendance.at[attendance[attendance['Id'] == Id].index.values, 'Status'] = 'MCR'
elif check == 'No':
print('Not clocked OUT')
Taceback Error message
======================
Traceback (most recent call last):
File "main.py", line 57, in <module>
mainMenu()
File "main.py", line 38, in mainMenu
mainMenu()
File "main.py", line 43, in mainMenu
mainMenu()
File "main.py", line 48, in mainMenu
mainMenu()
File "main.py", line 47, in mainMenu
Recognize.recognize_attendence()
File "C:\Users\Henrio\Desktop\Face Recognition and Biometric Attendance Solution\Attendance-Capture-System-Using-Face-Recognition-main\Recognize.py", line 92, in recognize_attendence
duration = datetime.datetime.strptime(co[-1], FMT) - datetime.datetime.strptime(ci[-1], FMT)
File "C:\Python3.7\lib\_strptime.py", line 577, in _strptime_datetime
tt, fraction, gmtoff_fraction = _strptime(data_string, format)
File "C:\Python3.7\lib\_strptime.py", line 359, in _strptime
(data_string, format))
ValueError: time data ')' does not match format '%H:%M:%S'
(env) C:\Users\Henrio\Desktop\Face Recognition and Biometric Attendance Solution\Attendance-Capture-System-Using-Face-Recognition-main>
elif event == 'Clock OUT':
check = sg.PopupYesNo(' Are you clocking OUT?')
if check == 'Yes':
ts = time.time()
timeStamp = datetime.datetime.fromtimestamp(ts).strftime("%H:%M:%S")
attendance.at[attendance[attendance['Id'] == Id].index.values, 'Clock OUT Time'] = timeStamp
co = attendance.loc[attendance[attendance['Id'] == Id].index.values, 'Clock OUT Time'].to_string().split(' ')
ci = attendance.loc[attendance[attendance['Id'] == Id].index.values, 'Clock IN Time'].to_string().split(' ')
aa = str(aa)[2:-2]
FMT = "%H:%M:%S"
line 92 ==> duration = datetime.datetime.strptime(co[-1], FMT) - datetime.datetime.strptime(ci[-1], FMT)
attendance.at[attendance[attendance['Id'] == Id].index.values, 'Duration'] = duration
d = datetime.datetime.strptime(lecture, FMT) - datetime.datetime.strptime(str(duration), FMT)
if int(str(d).split(':')[1]) in range(-5, 6):
attendance.at[attendance[attendance['Id'] == Id].index.values, 'Status'] = 'Present'
else:
attendance.at[attendance[attendance['Id'] == Id].index.values, 'Status'] = 'MCR'
elif check == 'No':
print('Not clocked OUT')
Look at what the traceback says at the end:
ValueError: time data ')' does not match format '%H:%M:%S'
Looking further up to where is mentions one of the lines in your code:
duration = datetime.datetime.strptime(co[-1], FMT) - datetime.datetime.strptime(ci[-1], FMT)
I can’t tell which one is the problem, but either co[-1]
or ci[-1]
is ')'
.
You should check what co
and ci
are and where their values come from and debug from there.
co from the code is clock_out and ci is clock_In
The entire code is attendance system
What are their values? You’re splitting them on ' '
to get a list and then assuming that the last item is a time with a specific format, but it’s a ')'
. Clearly, it’s not what you were expecting, so what are the actual values of clock_in and clock_out?