Python Forum

Full Version: CSV date format
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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,
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)