Reputation: 1690
I'm trying to convert a data string that comes from a data set into a datetime object and I am getting the following error,
This error is quite different than others I saw on other questions like Python- strptime ValueError unconverted data remains: :00
import datetime
date_ = '2021-08-31 21:14:39.901557+00'
source_date = datetime.datetime.strptime(date_, '%Y-%m-%d %H:%M:%S.%f')
My error
ValueError: unconverted data remains: +00
Upvotes: 2
Views: 2896
Reputation: 111
as @Bakuriu mentioned this is invalid
date_ = '2021-08-31 21:14:39.901557+00'
To fix it you should add the remaining zeros and add a %z to the strptime
date_ = '2021-08-31 21:14:39.901557+0000'
source_date = datetime.datetime.strptime(date_, '%Y-%m-%d %H:%M:%S.%f%z')
Upvotes: 2