Results 1 to 3 of 3
  1. #1
    toollady22 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Nov 2014
    Location
    Newport News
    Posts
    3

    Calculating elasped time


    I have been trying to create an employee time card with the fields: start/ finish/hrsworked/rate/totalpay on a test database. So far I think I have figured out how to accomplish the hours worked but it displays as time (5:00) I presume that is why I can not calculate the totalpay because that is currency. I have even attempted to make a query for that textbox on the form but to no avail. Help I am still learning

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,954
    Is hrsworked a calculated field? The elapsed time should be calculated with the start and finish fields using DateDiff function. The result should be a decimal hours value. Show the expression that calculates hrsworked.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    Like this:

    Note that DateDiff() is very literal in its calculations. If you use the Interval for Hours (h) it simply subtracts the two hours, so if StartTime is 12:00 (noon) and the EndTime is 13:59, then

    Datediff("h",StartTime, EndTime)


    will return 1 hour, because 13-12 = 1, although you're actually talking about 1 hour and 59 minutes. So what you have to do is use the Interval for Minutes (n) and then parse it into hours and fraction of hours.

    So, the syntax of

    Format(DateDiff("n", StartTime, EndTime) / 60,"0.00")

    will return 1.98 hours.

    Also note that using Format() to limit the returned time to two decimal places actually returns this as Text, and if you are going to do more math with the elapsed time you may have to convert it back to a Number, using something like CDbl(). I say 'maybe' because Access can be flexible in this area; sometimes if it looks like a Number it will be treated like a Number.

    Linq ;0)>
    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 8
    Last Post: 08-24-2012, 01:54 AM
  2. Calculating Time
    By jlclark4 in forum Forms
    Replies: 0
    Last Post: 04-25-2011, 09:04 AM
  3. Calculating Elapsed Time
    By jo15765 in forum Forms
    Replies: 8
    Last Post: 04-15-2011, 07:00 PM
  4. Replies: 12
    Last Post: 02-22-2011, 03:39 PM
  5. Need help with calculating Time total
    By Monoceros in forum Reports
    Replies: 1
    Last Post: 04-20-2009, 12:44 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums