Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Date format issue
#1
Hi All,

My apologies in advance if my code is sloppy, just getting back into programming from a LONG break.

I'm having some trouble with datetime.strptime module in my Python3 script - which is running on a Raspberry Pi 3. I keep getting the error 'ValueError: time data '' does not match format '%Y-%m-%d %H:%M:%S.%f''

The trouble code in my script is as follows-

from datetime import datetime, timedelta

if os.path.isfile(log_file): # First check if file exists.
        with open(log_file, 'r') as f:
            date = f.read()
            date_to_datetime = datetime.strptime(date, "%Y-%m-%d %H:%M:%S.%f")

            if datetime.now() < date_to_datetime + timedelta(minutes=1):
                return

    # Update the email log.
    with open(log_file, 'w') as f:
        f.write(str(datetime.now()))
Any and all help would be greatly appreciate. If you have a suggestion on how to fix my issue, please revise my code so it's as straight forward for me to understand as best as possible. Thank you!

- TD
Reply


Messages In This Thread
Date format issue - by the_dude - Jun-04-2019, 03:05 AM
RE: Date format issue - by Gribouillis - Jun-04-2019, 04:42 AM
RE: Date format issue - by buran - Jun-04-2019, 04:54 AM
RE: Date format issue - by perfringo - Jun-04-2019, 06:27 AM
RE: Date format issue - by the_dude - Jun-05-2019, 01:01 PM
RE: Date format issue - by buran - Jun-05-2019, 01:07 PM
RE: Date format issue - by Gribouillis - Jun-05-2019, 04:20 PM
RE: Date format issue - by the_dude - Jun-06-2019, 07:41 PM
RE: Date format issue - by snippsat - Jun-06-2019, 08:26 PM
RE: Date format issue - by buran - Jun-06-2019, 08:43 PM
RE: Date format issue - by the_dude - Jun-06-2019, 11:29 PM
RE: Date format issue - by snippsat - Jun-07-2019, 06:27 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Invalid Date Format fo Cached Files jland47 1 262 May-22-2024, 07:04 PM
Last Post: deanhystad
  Compare current date on calendar with date format file name Fioravanti 1 444 Mar-26-2024, 08:23 AM
Last Post: Pedroski55
  Python date format changes to date & time 1418 4 877 Jan-20-2024, 04:45 AM
Last Post: 1418
  Modifying a date format jehoshua 17 3,501 Oct-29-2022, 08:44 PM
Last Post: jehoshua
  Issue in changing data format (2 bytes) into a 16 bit data. GiggsB 11 2,942 Jul-25-2022, 03:19 PM
Last Post: deanhystad
  Date format error getting weekday value Aggie64 2 1,531 May-29-2022, 07:04 PM
Last Post: Aggie64
  Convert Date to another format lonesoac0 2 1,784 Mar-17-2022, 11:26 AM
Last Post: DeaD_EyE
  Format SAS DATE Racer_x 0 1,075 Feb-09-2022, 04:44 PM
Last Post: Racer_x
  Date Conversion issue Racer_x 2 1,908 Jan-10-2022, 02:40 PM
Last Post: Racer_x
  How can I compare 2 format of date? korenron 4 1,669 Dec-21-2021, 12:40 PM
Last Post: korenron

Forum Jump:

User Panel Messages

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