



So the method calculates the new time by adding the two together, so the new time should be 23:51. '23:01' The second being an integer eg 50. The user inputs the two values, the first being a string eg. Now, to convert the seconds difference from a timedelta into hours, just divide by 3600: > hours_difference = abs(start_time - end_time).total_seconds() / 3600.0 python: convert two strings of h & m into 24 hour time format. I want to get a list of date objects of them, but when I try to transform the example string into a date object, I have to transform it from Mon, 24:00:00 to Tue, 00:00:00. Subtracting one datetime from another gives you a timedelta object, and you can use abs to ensure the time difference is positive: > start_time - end_time I have a lot of date strings like Mon, 24:00:00 and some of them are in 00-23 hour format and some of them in 01-24 hour format. I'll assume you have no trouble writing a loop, to iterate through the values in.
#Convert string to date python 24 hour time code
> start_time = datetime.datetime(2011,3,10,15,45,48) The key to this code is to use the library function time.strptime () to parse the 24-hour string representations into a time.structtime object, then use library function time.strftime () to format this structtime into a string of your desired 12-hour format. Let's assume that you have your two dates and times as datetime objects (see datetime.datetime): > import datetime
