Thursday, 12 September 2013

Difference between two times python

Difference between two times python

I can't get this working. I'm tired of searching, but I can't find
anything. I don't have a date, I only have time (01:45, 05:30).
I'm only using the library 'Time', currently I have the code above, which
gives me the minutes between the hours. But this is not enough.
In this example, the final result should be:
225 minutes
3 hours (rounded down)
hour_beg = '01:45'
hour_close = '05:30'
hours_begin = int(hour_beg.split(':')[0]) # 01
minutes_begin = int(hour_beg.split(':')[1]) # 45
hours_end = int(hour_close.split(':')[0]) # 05
minutes_end = int(hour_close.split(':')[1]) # 30
total_minutes = abs((hours_begin - hours_end ) * 60)
How can I accomplished that?

No comments:

Post a Comment