Python Forum
String formatting (strptime) issues
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
String formatting (strptime) issues
#1
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'
Larz60+ write Jan-05-2023, 05:06 PM:
In the future, please use BBCode tags for your code, input, output and/or errors rather than posting images.

Attached Files

Thumbnail(s)
   
Reply
#2
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.
Sig:
>>> import this

The UNIX philosophy: "Do one thing, and do it well."

"The danger of computers becoming like humans is not as great as the danger of humans becoming like computers." :~ Konrad Zuse

"Everything should be made as simple as possible, but not simpler." :~ Albert Einstein
Reply
#3
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}'
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Formatting a date time string read from a csv file DosAtPython 5 1,300 Jun-19-2023, 02:12 PM
Last Post: DosAtPython
  confused about string formatting barryjo 7 2,006 Mar-06-2022, 02:03 AM
Last Post: snippsat
  string formatting barryjo 7 2,074 Jan-02-2022, 02:08 AM
Last Post: snippsat
  Help with string formatting in classes brthurr 6 9,401 Dec-17-2021, 04:35 PM
Last Post: Jeff900
  OpenPyXl formatting issues kpayney1 0 1,688 Nov-26-2021, 01:56 AM
Last Post: kpayney1
  Question on HTML formatting with set string in message Cknutson575 3 3,507 Mar-09-2021, 08:11 AM
Last Post: Cknutson575
  Formatting issues? Mark17 1 1,700 Dec-30-2020, 04:17 PM
Last Post: Mark17
  Extracting year from a string using strptime and datetime builtin Drone4four 3 8,728 Aug-11-2020, 12:02 PM
Last Post: ndc85430
  smtplib: string formatting not carrying over to email ClassicalSoul 1 2,664 Apr-22-2020, 09:58 PM
Last Post: bowlofred
  f-string issues in 3.6.9 (?) KSterner 4 2,245 Feb-08-2020, 09:41 PM
Last Post: metulburr

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020