-1

I want the diff between two timestamps which are available to me as list of strings.

date_list = ['Tue Sep 25 21:12:32 PDT 2018', 'Tue Sep 25 21:15:27 PDT 2018']

How do I get the difference in minutes or in hours ?

I saw some examples, but they are using different format of UNIX timestamp. I can't change the given date format.

  • This post is being discussed on meta https://meta.stackoverflow.com/questions/374931/what-should-i-do-if-suspect-the-chosen-duplicate-post-is-not-correct?cb=1 ; correct duplicate might be https://stackoverflow.com/questions/23704826/python-time-string-does-not-match-format – Joshua Oct 05 '18 at 22:47

1 Answers1

1

I suggest to use dateutil. For instance

from dateutil import parser

d1 = parser.parse(date_list[0])
d2 = parser.parse(date_list[1])

at this point d1 and d2 are standard datetime objects and you can use the standard methods/operators to operate on them

Massimo Costa
  • 1,864
  • 15
  • 23