Results 1 to 8 of 8
  1. #1
    Delta729 is offline Advanced Beginner
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Nov 2010
    Location
    Los Angeles
    Posts
    95

    Sql Expression Help

    Help with the math please.



    I'm trying to calculate the difference between start and end time, which works fine with:

    Total Time: DateDiff("n",[tblTaskTimes]![StartTime],[tblTaskTimes]![EndTime])

    However, this is for a database that calculates billable time in 10th of an hour. So, for example, 1 hours would be 1, 30 minutes would be .5, less than 6 minutes would be .1.

    The format for this expression is set up to a general number, if that matters.

    It's gotta be something in the formula like multiplying this by 24 (for 24 hours) and then dividing by something. Nothing I'm trying is working. Any ideas?

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,943
    If you want to round to the nearest tenth of an hour:

    Say the DateDiff calc returns 1000 minutes, represented by x.

    Int(x/60) + Round((x mod 60)/60,1)

    Returns 16.7 hours

    Be aware that Round() function in Access uses even/odd (banker's rounding) rule.

    Round(3.45, 1) will return 3.4

    Round(3.46, 1) will return 3.5

    Round(3.35, 1) will return 3.4

    However, if you want to always round up to the nearest tenth, that is a little more complicated. 7 minutes should round to .2 instead of .1?
    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
    Delta729 is offline Advanced Beginner
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Nov 2010
    Location
    Los Angeles
    Posts
    95
    That's something I hadn't thought about. Basically:
    1 second up to 5 minutes 59 seconds would be .1
    6 minutes thru 11 minutes 59 Minutes would be .2
    etc.

    Basically, I wouldn't want to round, correct? (I'm lost and confused)?

  4. #4
    Delta729 is offline Advanced Beginner
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Nov 2010
    Location
    Los Angeles
    Posts
    95
    Okay, I've changed this so it will show total minutes on one expression:
    Total Time: DateDiff("n",[tblTaskTimes]![StartTime],[tblTaskTimes]![EndTime])
    Again, this works fine and give the total minutes.

    And then calculate Billable or total minutes to roundup to nearest 10th of an hour with:
    Billable: Int([Total Time]/60)+Round(([Total Time] Mod 60)/60,1)

    But the billable isn't working correctly. How do I round this up?Any suggestions on how to fix this? I'm very much a beginner in Access, so please, reply for the layman.

  5. #5
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    First, I would advise not using spaces in object names.

    Try this:
    Code:
    Billable: Int([TotalTime]/60)+Round(([TotalTime] Mod 60)/60+0.04,1)
    NOTE: No spaces in "TotalTime"

  6. #6
    Delta729 is offline Advanced Beginner
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Nov 2010
    Location
    Los Angeles
    Posts
    95
    That's great and looks as though it's working, but that lost me. What does the +0.04 do? I kindof have the prior info from June7 figured out, but why add 0.04 in?

  7. #7
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    It forces the rounding to round up.

    You said: "1 second up to 5 minutes 59 seconds would be .1"

    If you have a start time of 8:30 and an end time of 8:32 what should the billable time be?
    Actual time is 0.03333333333. Rounding would result in 0.

    Now add 0.03333333333 +0.04
    This results in .07333333333
    Round that to 1 decimal results in .1

  8. #8
    Delta729 is offline Advanced Beginner
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Nov 2010
    Location
    Los Angeles
    Posts
    95
    Awesome, thanks again.

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

Similar Threads

  1. Replies: 5
    Last Post: 09-25-2013, 09:35 AM
  2. Replies: 2
    Last Post: 11-20-2012, 03:21 AM
  3. Replies: 4
    Last Post: 10-26-2012, 12:49 AM
  4. Replies: 1
    Last Post: 01-05-2012, 05:10 PM
  5. Looking for help with an expression
    By CoachBarker in forum Queries
    Replies: 3
    Last Post: 11-25-2010, 05:17 AM

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