X   Site Message
(Message will auto close in 2 seconds)

Welcome to UtterAccess! Please ( Login   or   Register )

Custom Search
   Reply to this topicStart new topic
> Calculate Driving Time, Access 2013    
post Feb 5 2018, 10:08 AM

Posts: 65
Joined: 5-August 15
From: Ringgold, GA. USA

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..
Go to the top of the page
post Feb 5 2018, 10:16 AM

UA Admin
Posts: 33,506
Joined: 20-June 02
From: Newcastle, WA

TravelTime = [TravelTime]\60 & " Hours " & Format([TravelTime] Mod 60,"\.00") & " Minutes"

My Real Name Is George. Grover Park Consulting is where I do business.
How to Ask a Good Question
Beginning SQL Server
Visit My Blog on Facebook
Go to the top of the page
post Feb 5 2018, 10:56 AM

Posts: 18,324
Joined: 29-March 05
From: Wisconsin


I -think- this should return the string you're looking for:

Public Function DriveTime(intTotalMiles As Integer, intMPH As Integer) As String

'   Total hours:
    DriveTime = intTotalMiles / intMPH
'   Hours and minutes:
    DriveTime = Int(DriveTime) & " Hours " & Round((DriveTime - Int(DriveTime)) * 60, 0) & " Minutes"

End Function

What threw me off was your example. Driving at 55mph for 30 hours 45 minutes should take you 1691.25 miles, not 1655. If I've got my maths wrong, please let me know. (30.75 * 55 = 1,691.25)


(;,;) Li'l Cthulu says: Please talk about what you're trying to do, as well as how you're doing it.
Changing your real table name to "Table1" and your real form name to "Form1" in your posts makes it more difficult to understand what's going on, not easier.
Guidelines for Posting Questions
Go to the top of the page
post Feb 5 2018, 11:21 AM

Posts: 65
Joined: 5-August 15
From: Ringgold, GA. USA

Thanks for your help. I think I have it working now.

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
Go to the top of the page

Custom Search
RSSSearch   Top   Lo-Fi    24th September 2018 - 04:32 AM