Python Forum
Formatting a date time string read from a csv file
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Formatting a date time string read from a csv file
#1
L.S.,

I'm rather new to python-programming. I'm trying to remove the time info from a date time string read from a csv-file. My impression is that to achieve this, I have to use the strptime() function.

The test-script i'm using:
from datetime import datetime

my_datetime ='2023-06-15 07:26:50'
my_date = datetime.strptime(my_datetime, '%Y-%m-%d' )
print(my_date)
The error message I get in line 4:
Error:
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/_strptime.py", line 352, in _strptime raise ValueError("unconverted data remains: %s" % ValueError: unconverted data remains: 07:26:50
What I want to achieve is that 'my_date' contains the string '2023-06-15' without the time info of 'my_datetime'.

Who can help me with this issue?
Thanks in advance
Reply


Messages In This Thread
Formatting a date time string read from a csv file - by DosAtPython - Jun-19-2023, 10:59 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Connecting to Remote Server to read contents of a file ChaitanyaSharma 1 242 May-03-2024, 07:23 AM
Last Post: Pedroski55
  Compare current date on calendar with date format file name Fioravanti 1 291 Mar-26-2024, 08:23 AM
Last Post: Pedroski55
  Date Time Series Help...Please spra8560 2 412 Feb-01-2024, 01:38 PM
Last Post: spra8560
  Python date format changes to date & time 1418 4 679 Jan-20-2024, 04:45 AM
Last Post: 1418
  Recommended way to read/create PDF file? Winfried 3 2,953 Nov-26-2023, 07:51 AM
Last Post: Pedroski55
  python Read each xlsx file and write it into csv with pipe delimiter mg24 4 1,560 Nov-09-2023, 10:56 AM
Last Post: mg24
  Need to replace a string with a file (HTML file) tester_V 1 796 Aug-30-2023, 03:42 AM
Last Post: Larz60+
  Downloading time zone aware files, getting wrong files(by date))s tester_V 9 1,095 Jul-23-2023, 08:32 AM
Last Post: deanhystad
  read file txt on my pc to telegram bot api Tupa 0 1,161 Jul-06-2023, 01:52 AM
Last Post: Tupa
  parse/read from file seperated by dots giovanne 5 1,160 Jun-26-2023, 12:26 PM
Last Post: DeaD_EyE

Forum Jump:

User Panel Messages

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