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
  Compare current date on calendar with date format file name Fioravanti 1 228 Mar-26-2024, 08:23 AM
Last Post: Pedroski55
  Python date format changes to date & time 1418 4 605 Jan-20-2024, 04:45 AM
Last Post: 1418
  Modifying a date format jehoshua 17 2,978 Oct-29-2022, 08:44 PM
Last Post: jehoshua
  Date format error getting weekday value Aggie64 2 1,423 May-29-2022, 07:04 PM
Last Post: Aggie64
  Convert Date to another format lonesoac0 2 1,672 Mar-17-2022, 11:26 AM
Last Post: DeaD_EyE
  Format SAS DATE Racer_x 0 995 Feb-09-2022, 04:44 PM
Last Post: Racer_x
  How can I compare 2 format of date? korenron 4 1,525 Dec-21-2021, 12:40 PM
Last Post: korenron
  Date format and past date check function Turtle 5 4,254 Oct-22-2021, 09:45 PM
Last Post: deanhystad
  Print first day of the week as string in date format MyerzzD 2 2,018 Sep-29-2021, 06:43 AM
Last Post: MyerzzD
  String to Date format SAF 2 2,459 Apr-06-2021, 02:09 PM
Last Post: snippsat

Forum Jump:

User Panel Messages

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