May 26th, 2006, 5:51 PM
|
#4
|
|
Professional Programmer
Join Date: Feb 2005
Posts: 434
Rep Power: 4 
|
Quote:
|
Originally Posted by Arevos
There's an easier method: use the datetime module.
import datetime
six_thirty = datetime.datetime(2006, 5, 26, 6, 30)
two_thirty = datetime.datetime(2006, 5, 26, 14, 30)
difference = two_thirty - six_thirty
print "Hours difference:", difference.seconds / 60 / 60 One thing to note is that you have to specify a date as well as a time. You cannot find the difference between two datetime.time modules. This is probably because the number of seconds between two times is sometimes different from the usual. At daylight saving time, for instance, or in the rare case of leap-seconds.
|
The problem here comes when you ask the user to input the times like 6:30am and 2:30pm. Now you have to prep the input for the time tuples!
__________________
I looked it up on the Intergnats!
Last edited by Dietrich; May 26th, 2006 at 6:18 PM.
|
|
|