Cybertron
Cybertron

Reputation: 155

Datetime conversion format

I converted the datetime from a format '2018-06-22T09:38:00.000-04:00' to pandas datetime format

i tried to convert using pandas and got output but the output is

o/p: 2018-06-22 09:38:00-04:00

date = '2018-06-22T09:38:00.000-04:00'
dt = pd.to_datetime(date)

expected result: 2018-06-22 09:38

actual result: 2018-06-22 09:38:00-04:00

Upvotes: 1

Views: 47

Answers (1)

jezrael
jezrael

Reputation: 862471

There is timestamps with timezones, so if convert to UTC by Timestamp.tz_convert, times are changed:

date = '2018-06-22T09:38:00.000-04:00'
dt = pd.to_datetime(date).tz_convert(None)
print (dt)
2018-06-22 13:38:00

So possible solution is remove last 6 values in datetimes:

dt = pd.to_datetime(date[:-6])
print (dt)
2018-06-22 09:38:00

Upvotes: 2

Related Questions