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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Calculate working hours:mins 1

Status
Not open for further replies.

cumap

IS-IT--Management
Jul 9, 2007
268
0
0
US
Hello,

I'm creating a timeclock and need to calculate total working time in the end of the days. This is what I came up
Code:
fhours = DATEDIFF("h",rs("clockIn"),rs("lunchOut"))
fmins = Right("0" & (DATEDIFF("n",rs("clockIn"),rs("lunchOut")) - DATEDIFF("h",rs("clockIn"),rs("lunchOut"))*60),2)
shours = DATEDIFF("h",rs("lunchIn"),rs("clockOut"))
smins = Right("0" & (DATEDIFF("n",rs("lunchIn"),rs("clockOut")) - DATEDIFF("h",rs("lunchIn"),rs("clockOut"))*60),2)
thours = cint(fhours) + cint(shours)
tmins = cint(fmins) + cint(smins)
if tmins > 60 then
  thour = tmins/60
  tmins = tmins - (thour*60)
  thours = thours + thour
end if
finalresult = thours&":"&Right("0" & (tmins),2)

Is there a better and shorter way to result this?

Thanks!
 
You could do both the DateDiff statements in minutes, add the minutes and only convert to hours when you want to display the answer.
Code:
fmins = DATEDIFF("n",rs("clockIn"),rs("lunchOut"))
smins = DATEDIFF("h",rs("lunchIn"),rs("clockOut"))
tmins = cint(fmins) + cint(smins)
finalresult= (tmins \ 60 & ":" & Right("00" & Cstr(tmins mod 60 ),2))

___________________________________________________________
If you want the best response to a question, please check out FAQ222-2244 first.
'If we're supposed to work in Hex, why have we only got A fingers?'
Drive a Steam Roller
Steam Engine Prints
 
Perfect... why didn't think of that instead of complicating thing up? Go figure!!!
Thanks johnwm!!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top