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
#5
>>> from datetime import datetime
my_datetime ='2023-06-15 07:26:50'
>>> my_date = datetime.strptime(my_datetime, '%Y-%m-%d %H:%M:%S').date()
>>> my_date
datetime.date(2023, 6, 15)
>>> my_date.strftime('%Y-%m-%d')
'2023-06-15'
Also if you only want the string
>>> my_datetime ='2023-06-15 07:26:50'
>>> my_datetime.split()[0]
'2023-06-15'
buran likes this post
Reply


Messages In This Thread
RE: Formatting a date time string read from a csv file - by Gribouillis - Jun-19-2023, 12:18 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Formatting DateTime string and and converting it from AM/PM to 24 hours tester_V 2 257 Jun-08-2024, 05:16 PM
Last Post: tester_V
  Connecting to Remote Server to read contents of a file ChaitanyaSharma 1 488 May-03-2024, 07:23 AM
Last Post: Pedroski55
  Compare current date on calendar with date format file name Fioravanti 1 470 Mar-26-2024, 08:23 AM
Last Post: Pedroski55
  Date Time Series Help...Please spra8560 2 547 Feb-01-2024, 01:38 PM
Last Post: spra8560
  Python date format changes to date & time 1418 4 909 Jan-20-2024, 04:45 AM
Last Post: 1418
  Recommended way to read/create PDF file? Winfried 3 3,159 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,910 Nov-09-2023, 10:56 AM
Last Post: mg24
  Need to replace a string with a file (HTML file) tester_V 1 945 Aug-30-2023, 03:42 AM
Last Post: Larz60+
  Downloading time zone aware files, getting wrong files(by date))s tester_V 9 1,389 Jul-23-2023, 08:32 AM
Last Post: deanhystad
  read file txt on my pc to telegram bot api Tupa 0 1,314 Jul-06-2023, 01:52 AM
Last Post: Tupa

Forum Jump:

User Panel Messages

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