0

I am trying to take in a string for the time, for example "10:20", then take in a second string, for example "10:25", and calculate the difference.

I am finding the time functions in Python difficult to understand.

Any pointers would be gratefully received.

jonrsharpe
  • 115,751
  • 26
  • 228
  • 437
  • Have a look at `datetime`, specifically [`strptime`](https://docs.python.org/2/library/datetime.html#strftime-and-strptime-behavior). – jonrsharpe Sep 25 '14 at 10:43
  • 3
    Difficult to answer when we don't know what you find difficult to understand – EdChum Sep 25 '14 at 10:44
  • 1
    Hope you will find the answer here at this [link](http://stackoverflow.com/questions/3096953/difference-between-two-time-intervals-in-python) – d-coder Sep 25 '14 at 10:47

1 Answers1

1

you can use datetime module . this is elegant Pythonic way !

from datetime import datetime
s1 = '10:20'
s2 = '11:25' 
tformat = '%H:%M' # specify the format of your time string
diftime = datetime.strptime(s2, tformat) - datetime.strptime(s1, tformat)

print diftime
1:05:00
Mazdak
  • 105,000
  • 18
  • 159
  • 188