How do I calculate AM hours with PM hours to creat

# Thread: How do I calculate AM hours with PM hours to creat

1. Senior Member
Join Date
Dec 1969
Posts
218

## How do I calculate AM hours with PM hours to creat

I&#039m crating an online timesheet and I&#039m having trouble with calculating the hours.<BR><BR>For example, If Someone goes to work on monday, and arrives at 9 am, then takes a 30 minute lunch, and then leaves at 6 pm, how do I calculate that? Because the hours of a clock go from 12 O&#039clock then to 1 O&#039clock.<BR><BR>I&#039ve tried this for a week and I cant figure it out.<BR><BR>Thanks!<BR><BR>Marc

2. Senior Member
Join Date
Dec 1969
Posts
1,315

## RE: How do I calculate AM hours with PM hours to c

Marc,<BR>I am realitively new at ASP and VBScript, but I think I know how to help you out. There is a function in VB called date or getdate (something like that) that returns the current date. There also is a function that does the same with time, only it returns it in a Military format. So, for your example, if someone came in at 9:00 (still 9:00 in Military time) took a half hour lunch, and left at 6:00 (18:00 in Miltary time), here&#039s what I&#039d do:<BR><BR>dim Clock_In &#039start time<BR>dim Clock_Out &#039end time<BR>dim Hours_Worked<BR>dim lunch<BR><BR>&#039need to set lunch equal to 1/2 hour here<BR><BR>Hours_Worked = Clock_Out - Clock_In - lunch<BR>------------------------------------------------------------<BR>For more info on that Time function, check out this source:<BR><BR>http://msdn.microsoft.com/scripting/<BR><BR>click on VBScript, then Documentation, then scroll down and click functions, and I believe the name of it is Time. Let me know if this helps!!!<BR><BR>Happy Programming,<BR><BR>JOHN

3. KPW Guest

## RE: How do I calculate AM hours with PM hours to c

I agree with John&#039s tactic of using military time. Here is how the code I wrote to solve your problem.<BR><BR>&#060;%<BR><BR>Dim dTimeOut<BR>Dim dTimeBreak<BR>Dim dTimeIn<BR>Dim dHoursWorked<BR><BR>dTimeOut = FormatDateTime("6:00 PM",vbShortTime)<BR>dTimeBreak = .5&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#039 1/2 hour<BR>dTimeIn = FormatDateTime("9:00 AM",vbShortTime)<BR><BR>dHoursWorked = DateDiff("n",dTimeIn,dTimeOut)<BR><BR>dHoursWorked = (dHoursWorked/60) - dTimeBreak<BR><BR>Response.Write dHoursWorked<BR><BR>%&#062;<BR><BR>

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•