Time Calculations

1. Senior Member
Join Date
Dec 1969
Posts
287

## Time Calculations

Hi. I have to caluclate time difference. I use access db and i have two varialbes: clockin clockout. I need a difference between clockout - clockin to derive to hours worked. Clockin and clockout are time formats, but when I calculate it, i use hour function and it rounds everything to whole numbers. I need to see the quarter breakdown. let say someone worked 8.5 hours, currently i only show 8 instead of 8.5. here is my code for calculating:<BR><BR>&#060;td&#062;<BR>&#060;% = rsProds("clockin") %&#062;&#060;/td&#062;<BR>&#060;td&#062;<BR>&#060;% = rsProds("clockout") %&#062;&#060;/td&#062;<BR><BR><BR>&#060;td&#062;<BR>&#060;% = rsProds("Rate") %&#062;&#060;/td&#062;<BR> &#060;td&#062;=(f&#060;%=row%&#062;*1.5)&#060;/td&#062; <BR><BR><BR> &#060;td&#062;=e&#060;%=row%&#062;-d&#060;%=row%&#062;&#060;/td&#062; <BR> &#060;td&#062;=if(iserror(hour(h&#060;%=row%&#062; )),0,(hour(h&#060;%=row%&#062;)))&#060;/td&#062; <BR>&#060;td&#062;<BR>8&#060;/br&#062;<BR> &#060;td&#062;=IF(i&#060;%=row%&#062;&#062;j&#060; %=row%&#062;,i&#060;%=row%&#062;-j&#060;%=row%&#062;,0)&#060;/td&#062; <BR><BR> <BR> &#060;td&#062;=(i&#060;%=row%&#062;-k&#060;%=row%&#062;)*f&#060;%=row%&#062;&#060;/td&#062; <BR><BR><BR> &#060;td&#062;=k&#060;%=row%&#062;*g&#060;%=row%&# 062;&#060;/td&#062; <BR> &#060;td&#062;=l&#060;%=row%&#062;+m&#060;%=row%&# 062;&#060;/td&#062; <BR> <BR>&#060;% <BR> row = row + 1 <BR> rsProds.movenext <BR>loop <BR>%&#062; <BR>I am not sure how to deriv eto that .<BR>Thanks,<BR>PEtra.<BR>

2. Senior Member
Join Date
Dec 1969
Posts
16,931

## RE: Time Calculations

Click the "VBScript Reference" link on the left and look at the "DateDiff" function. You can use it to extract just the difference in hours between the two dates.<BR><BR>Craig.

3. Senior Member
Join Date
Dec 1969
Posts
287

## ??

I need the difference between time like 10:58 AM and 15:15PM<BR>not dates. Thanks

4. Senior Member
Join Date
Dec 1969
Posts
16,931

## If you actually...

...took my advice and went to the page I asked you to, you&#039;d notice in the description of the DateDiff function:<BR>http://msdn.microsoft.com/library/default.asp?url=/library/en-us/script56/html/vsfctdatediff.asp<BR>"Returns the number of intervals between two dates."<BR>The "interval" can be hours. If you pass it just a time, it&#039;ll treat them as occuring on the same day.<BR><BR>Craig.

5. Senior Member
Join Date
Dec 1969
Posts
287

## one more question

i changed it but is this how i put it in my code:<BR><BR> &#060;td&#062;DiffADate = " & DateDiff("h", clockout, clockin)<BR><BR><BR><BR><BR>td&#062; Thank you for all your help

6. Senior Member
Join Date
Dec 1969
Posts
287

## also

that calculation would show up in the cell, it wouldn&#039;t be only on the web. This is a download ot excel, so the calc has to be in the cell. <BR>Thanks again.

7. Senior Member
Join Date
Dec 1969
Posts
16,931

## RE: also

I&#039;m not sure what you&#039;re having problems with:<BR><BR>&#060;td&#062;&#060;%=DateDiff("h", clockout, clockin)%&#062;&#060;/td&#062;<BR><BR>Craig.

8. Senior Member
Join Date
Dec 1969
Posts
287

## It doesn't show any value

Craig:<BR><BR>Ok i have this code, but when I downloaded into excel it shows 0. Nothing calculates. Current code:<BR><BR><BR> &#060;td&#062;=e&#060;%=row%&#062;-d&#060;%=row%&#062;&#060;/td&#062; <BR> &#060;td&#062;&#060;%=DateDiff("h", clockout, clockin)%&#062;&#060;/td&#062; <BR><BR><BR><BR> Code Before:<BR> &#060;td&#062;=if(iserror(hour(h&#060;%=row%&#062; )),0,(hour(h&#060;%=row%&#062;)))&#060;/td&#062; <BR>(before code returned a number but rounded to the whole number).<BR><BR>Thanks,<BR>Petra.

9. Member
Join Date
Dec 1969
Posts
53

## RE: It doesn't show any value

if you are using <BR><BR>&#060;td&#062;&#060;%=DateDiff("h", clockout, clockin)%&#062;&#060;/td&#062; <BR>wont that produce a negative number<BR><BR>try switching around and see what you get<BR><BR>&#060;td&#062;&#060;%=DateDiff("h", clockin, clockout)%&#062;&#060;/td&#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
•