Morgan Allen Morgan Allen - 1 year ago 89
Python Question

Subtracting two datetime objects

I have one datetime object

2016-04-11 19:46:46-04:00


2016-04-25 09:35:18.464966
(this one is

How do I get them to the same format so I can subtract them?

Answer Source

You can use dateutil.parser.

from dateutil.parser import *
import datetime

date1="2016-04-11 19:46:46-04:00"
updated_date1=parse(date1, ignoretz=True) #Ignoring TimeZone
result=updated_date2 - updated_date1
print result