Convert elapsed time value into nearest 10th of an hour

Posted on 2006-04-04
Medium Priority
Last Modified: 2012-06-22
I have a variable called ElapsedTime which represents the number of seconds between the StartTime and the current time.  

    Dim ElapsedTime As Long
    ElapsedTime = Timer - StartTime

I want a function that convert this numer of seconds by rounding up to the nearest 10th of an hour, like this:

1-6 minutes = .1
6-12 minutes = .2
12-18 minutes = .3
18-24 minutes = .4
24-30 minutes = .5
30-36 minutes = .6
36-42 minutes = .7
42-48 minutes = .8
48-54 minutes = .9
54-60 minutes = 1.0
60-66 minutes = 1.1

What is the best way to accomplish this?  Thank you.
Question by:DanielAttard
  • 4
LVL 58

Expert Comment

ID: 16376145

You can use Round(dblElapsed, 1). BTW: if you declare ElapsedTime as Long, you will always get rounded seconds in your code. The conversion to long will be implicit in the assignation.
Timer returns a Single value.

LVL 58

Expert Comment

ID: 16376153
Sorry, misread. Let me try again...
LVL 58

Accepted Solution

harfang earned 2000 total points
ID: 16376162
One hour = 3600 seconds, so use:

    Round( ElapsedSeconds * 3600, 1 )


Author Comment

ID: 16376236
that was quick and simple.  thanks for the help.
LVL 58

Expert Comment

ID: 16376284
Still not what you seem to want... Your text says "to the nearest" but your sample says otherwise.

Perhaps: round to the nearest minute and then round up to the nearest 10th?

    ( ( Round(ElapsedSeconds / 60)  + 5 ) \ 6 ) / 10

Also, it should have been /3600 and not *3600 in my previous post, obviously ;)



Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
Suggested Courses

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question