Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Adding Time

Status
Not open for further replies.

gmagerr

Technical User
Aug 11, 2001
323
US
Hi guys, i'm trying to create an online timesheet for our employees. on the first page i have basically 2 dropdown list boxes, along with name and day etc... The Listbox on the left has the values of 12:00 AM to 11:00 AM the one on the right has the values of 12:00 PM to 11:00 PM. So when the user submits that, he goes to the second page.. and on that page i have this code

<% Dim TotalTime, Morning, MorningTime, Evening, EveningTime
Morning = Left(Request.Form(&quot;Morning&quot;), 1)
Evening = Left(Request.Form(&quot;Evening&quot;), 1)
MorningTime = CInt(Morning)
EveningTime = CInt(Evening)

TotalTime = MorningTime + EveningTime
Response.Write TotalTime
%>


So basically right now what it's doing is adding the numbers together, for instance 9 to 5 gives me 14 hours instead of 8. what do i need to do to make this work? thanks in advance.
 
Convert the time to 24hr

TotalTime = (EveningTime +12) - MorningTime
 
In the lists, associate the am/pm times with the 24hour number.
i.e. <OPTION VALUE=1>1 a.m.
<OPTION VALUE=2>2 a.m.
etc.....
<OPTION VALUE=13>1 p.m
<OPTION VALUE=14>2 p.m


then:

<% Dim TotalTime, Morning, MorningTime, Evening, EveningTime
MorningTime = Request.Form(&quot;Morning&quot;)
EveningTime = Request.Form(&quot;Evening&quot;)

TotalTime = EveningTime - MorningTime
Response.Write TotalTime
%>

or something like that. This isn't perfect if your workers worker over midnight (eg. from 11pm to 4am, then you would get a negative number). If thats the case, you have to add a bit.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top