from Tkinter import *
from datetime import datetime
from datetime import timedelta
import math
rate1 = str(35.34)
amp = 2.40
pmp = 2.50
signOnSun1 = raw_input("What time did you sign on Sunday: ");
signOffSun1 = raw_input("What time did you sign off Sunday: ");
if (signOnSun1 < 0600):
rate1 = rate1 + amp
elif (signOnSun1 > 1100):
rate1 = rate1 + pmp
elif (signOffSun1 > 1800):
rate1 = rate1 + pmp
else:
rate1 = 35.34
FMT = '%H%M'
timeWorkedSun1 = ( (datetime.strptime(signOffSun1, FMT)) - (datetime.strptime (signOnSun1, FMT)))
* I want to convert timeWorkedSun1 to a float so i can multiply it with rate1 but it seems to be the bane of my life. Any ideas?*
解决方案
timeWorkedSun1 is of type datetime.timedelta. Call its total_seconds method to translate it into a number of second (then divide by 3600 to get it in hours-and-fractions). I.e:
time_mul_by_hourly_rate = (timeWorkedSun1.total_seconds() / 3600.0) * rate1