2

I need to find the difference between two timestamps in minutes. I am using Python 3.6.

Here is my script:

import datetime
from dateutil import parser

indate = str(datetime.datetime.utcnow())
indate2 = parser.parse(indate)
indate3  = indate2.date()
intime = indate2.time()


outdate1 = "2019-10-16T06:38:55.000+0000"
outdate2 = parser.parse(outdate1)
outdate3  = outdate2.date()
outtime = outdate2.time()

### ---THEN  PRINT DIFFERENCE BETWEEN THE TWO IN MINUTES --- ###
Chüngel
  • 375
  • 4
  • 19
Kush
  • 39
  • 8
  • Possible duplicate of [How much time left to given date (days, hours, mins, s.)](https://stackoverflow.com/questions/58391143/how-much-time-left-to-given-date-days-hours-mins-s) – Trollsors Oct 16 '19 at 07:56
  • 1
    Possible duplicate of [Difference between two dates in Python](https://stackoverflow.com/questions/8419564/difference-between-two-dates-in-python) – gstukelj Oct 16 '19 at 08:05

2 Answers2

2

It will be advisable to ensure that they both have the same timezone:

 (indate2.astimezone(datetime.timezone.utc) - outdate2).total_seconds()/60
    Out[161]: 494.60840941666663
Onyambu
  • 67,392
  • 3
  • 24
  • 53
2

You need to remove the timezone awarenes from outdate2

print(indate2 - outdate2.replace(tzinfo=None))
Frank
  • 1,959
  • 12
  • 27