Python Forum
CSV date format - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: CSV date format (/thread-27317.html)



CSV date format - Kumarkv - Jun-03-2020

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,


RE: CSV date format - perfringo - Jun-03-2020

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)