need to compute change in time between start time and end time.(Python)
Question: I need to write a program that accepts a start time and end time and computes
the change between them in minutes. For example, the start time is 4:30 PM and
end time is 9:15 PM then the change in time is 285 min. How do I accomplish
this in Python? I only need to compute for a 24 hour period


Answer: Here's what you can do:

    
    
    from datetime import datetime
    
    
    def compute_time(start_time, end_time):
        start_datetime = datetime.strptime(start_time, '%I:%M %p')
        end_datetime = datetime.strptime(end_time, '%I:%M %p')
        return (start_datetime - end_datetime).seconds / 60
    
    
    print compute_time('9:15 PM', '4:30 PM')
    

prints `285`.

