1

I have start_time='Tue Jun 6 06:01:43 PDT 2017' and stop_time='Tue Jun 6 06:02:04 PDT 2017'. I need to calculate the difference between those 2 dates in seconds/minutes/hours OR hours:minutes:seconds

I have tried datetime(stop_time) - datetime(start_time) and I'm facing this error TypeError: an integer is required

Krishna
  • 1,027
  • 4
  • 21
  • 35

1 Answers1

3

You can use the dateutil to convert the string datetime to datetime object

Sample:

from dateutil import parser


start_time='Tue Jun  6 06:01:43 PDT 2017' 
stop_time='Tue Jun  6 06:02:04 PDT 2017'

dt_start = parser.parse(start_time)
dt_end = parser.parse(stop_time)

print dt_end - dt_start

Result:

0:00:21
Rakesh
  • 78,594
  • 17
  • 67
  • 103