Results 1 to 7 of 7
  1. #1
    Join Date
    Jul 2010
    Location
    GA.
    Posts
    23

    Calculate Driving time

    Can anyone help me out with this??




    I need to calculate Driving time:
    I need to Divide Total Miles by Speed and get the Total Hours and Minutes it will take to drive.


    I was trying this but not working: =[TravelTime]\60 & Format([TravelTime] Mod 60,"\.00")


    Like this: 1655 / 55 = 30:45 Hours


    What I would really like is: 1655 / 55 = 30 Hours 45 Minutes


    Thanks for any help..

  2. #2
    aytee111 is offline Competent At Times
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936

  3. #3
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,977
    Sorry to disillusion you but the answer is 30.091 hours or 30 hours 5 minutes!

    Code:
    Function DrivingTime()
    
    Dim TravelTime As Double
    Dim TotalMiles As Double, Speed As Double
    
    'example values as supplied
    TotalMiles = 1655
    Speed = 55
    
    'TravelTime = TotalMiles / Speed
    'Debug.Print TravelTime
    
    
    DrivingTime = CInt(TotalMiles / Speed) & " hours " & CInt(60 * (TotalMiles Mod Speed) / Speed) & " minutes"
    Debug.Print DrivingTime
        
    End Function
    Last edited by isladogs; 02-05-2018 at 09:55 AM. Reason: Fixed error in formula
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  4. #4
    davegri's Avatar
    davegri is online now Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,413
    I believe your example is wrong. It should be 30 hrs 5 minutes.
    See attached DB for calculations:TimeElapsed-v2.zip

  5. #5
    Join Date
    Jul 2010
    Location
    GA.
    Posts
    23
    Thank you Ridders52
    That works Great.
    Thank you so much.

  6. #6
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,977
    You're welcome.
    I spent several minutes trying to work out how on earth you got 30 Hours 45 Minutes!

    If you want a more generic solution, something like this could be used

    Code:
    Function DrivingTime(TotalMiles As Double, Speed As Double) As String
    
    DrivingTime = CInt(TotalMiles / Speed) & " hours " & CInt(60 * (TotalMiles Mod Speed) / Speed) & " minutes"
    'Debug.Print DrivingTime
    
    End Function
    Example usage: DrivingTime (1655, 55)

    NOTE: I haven't looked at davegri's solution and he may well have done something very similar
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  7. #7
    Join Date
    Jul 2010
    Location
    GA.
    Posts
    23
    I was just using 30 Hours 45 Minutes as an example
    that I wanted to show Hours and Minutes..

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

Similar Threads

  1. Replies: 4
    Last Post: 10-28-2016, 07:57 AM
  2. Calculate time difference
    By desireemm1 in forum Access
    Replies: 19
    Last Post: 10-27-2014, 12:06 PM
  3. Replies: 0
    Last Post: 09-12-2013, 01:19 PM
  4. Replies: 42
    Last Post: 03-01-2013, 06:58 AM
  5. Calculate time
    By funkygoorilla in forum Access
    Replies: 19
    Last Post: 08-25-2011, 09:34 PM

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