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

I have a CSV with two columns with a date and float value
The date format is 2019/04/02 Tuesday 08:00:00
yyyy/MM/dd EEEE HH:mm:ss

How to convert this to date object from CSV date column.

Thanks,
Reply
#2
Something like this:

>>> import datetime                                                                                                                 
>>> datetime.datetime.strptime('2019/04/02 Tuesday 08:00:00', "%Y/%m/%d %A %H:%M:%S")                                               
datetime.datetime(2019, 4, 2, 8, 0) 
If only date is required, then .date() could be used for converting:

>>> datetime.datetime.strptime('2019/04/02 Tuesday 08:00:00', "%Y/%m/%d %A %H:%M:%S").date()                                        
datetime.date(2019, 4, 2) 
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy

Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
Exclamation Date format convert problem for SQL server eotret 5 1,905 Aug-09-2024, 07:19 AM
Last Post: Pedroski55
  Invalid Date Format fo Cached Files jland47 1 962 May-22-2024, 07:04 PM
Last Post: deanhystad
  Compare current date on calendar with date format file name Fioravanti 1 1,867 Mar-26-2024, 08:23 AM
Last Post: Pedroski55
  Python date format changes to date & time 1418 4 2,505 Jan-20-2024, 04:45 AM
Last Post: 1418
  Modifying a date format jehoshua 17 5,765 Oct-29-2022, 08:44 PM
Last Post: jehoshua
  Date format error getting weekday value Aggie64 2 2,054 May-29-2022, 07:04 PM
Last Post: Aggie64
  Convert Date to another format lonesoac0 2 2,364 Mar-17-2022, 11:26 AM
Last Post: DeaD_EyE
  Format SAS DATE Racer_x 0 1,498 Feb-09-2022, 04:44 PM
Last Post: Racer_x
  How can I compare 2 format of date? korenron 4 2,284 Dec-21-2021, 12:40 PM
Last Post: korenron
  Date format and past date check function Turtle 5 9,468 Oct-22-2021, 09:45 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

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