Hi, I'm writing a program that totals how long someone has worked by the starting time and the ending time.
It DOES work if the times entered are both AM or PM. Like if they worked from 2:00 to 9:10, it tells me the right answer of 7 hours and 10 minutes. But if they work from 11:20 to 9:15 it tells me that they worked -2 hours and -5 minutes, and gives me the incorrect total at the end of the code after the hours have been entered for every day.
Here the code. I don't know how to go about adding AM and PM. I'm very new to Python (1 week) but I catch on fast.
Can anyone help?
from string import *
import os
print "When did they clock in Monday? Use HH:MM format."
#Clock in time is what you type in. Entered as HH:MM.
clockinM = (raw_input())
print "When did they clock out Monday?"
#Clock out time is what you type in.
clockoutM = (raw_input())
#Splits the clock in time at the :
SsplitM = (split(clockinM,":"))
#Splits the clock out time at the :
EsplitM = (split(clockoutM,":"))
#The starting hours for Monday is part 0 of the split; the section in bracket. [HH]:MM
startHrsM = int(SsplitM[0])
#The starting minutes for Monday is part 1 of the split; the section in brackets.HH:[MM]
startMinM = int(SsplitM[1])
endHrsM = int(EsplitM[0])
endMinM = int(EsplitM[1])
#The total minutes worked on Monday is the ending minutes minus the starting minutes.
totalMinM = int(EsplitM[1])-int(SsplitM[1])
#The total hours worked on Monday is the ending hours minus the starting hours.
totalHrsM = int(EsplitM[0])-int(SsplitM[0])
#Print the results
print "They worked",totalHrsM,"hours and",totalMinM,"minutes Monday."