I have two datetime objects created by strptime in Python:
date_string = "Wed, 18 Dec 2013 09:30:00 GMT"
date = datetime.datetime.strptime(date_string, "%a, %d %b %Y %H:%M:%S %Z")
and
end_date_string = "Wed, 18 Dec 2013 10:15:00 GMT"
end_date = datetime.datetime.strptime(end_date_string, "%a, %d %b %Y %H:%M:%S %Z")
Datetime objects are created successfully so i get
>>>date
datetime.datetime(2013, 12, 18, 9, 30)
>>>end_date
datetime.datetime(2013, 12, 18, 10, 15)
I want to count the minutes the two datetimes differ. I do
diff = end_date - date
and i get
datetime.timedelta(0)
So it says that they are the same dates?No difference at all? Also seconds property is zero
>>>diff.seconds
0
How can this be made to work?
import datetime
date_string = "Wed, 18 Dec 2013 09:30:00 GMT"
date = datetime.datetime.strptime(date_string, "%a, %d %b %Y %H:%M:%S %Z")
end_date_string = "Wed, 18 Dec 2013 10:15:00 GMT"
end_date = datetime.datetime.strptime(end_date_string, "%a, %d %b %Y %H:%M:%S %Z")
print (end_date-date).total_seconds()
Gives
2700.0
it's kinda weird, i get the correct result:
>>> date_string = "Wed, 18 Dec 2013 09:30:00 GMT"
>>> date = datetime.datetime.strptime(date_string, "%a, %d %b %Y %H:%M:%S %Z")
>>> end_date_string = "Wed, 18 Dec 2013 10:15:00 GMT"
>>> end_date = datetime.datetime.strptime(end_date_string, "%a, %d %b %Y %H:%M:%S %Z")
>>> diff = end_date - date
>>> diff
datetime.timedelta(0, 2700)
>>> diff.seconds
2700
is this the whole code?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With