Convert elapsed time value into nearest 10th of an hour

Posted on 2006-04-04
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
    LVL 58

    Expert Comment


    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

    Sorry, misread. Let me try again...
    LVL 58

    Accepted Solution

    One hour = 3600 seconds, so use:

        Round( ElapsedSeconds * 3600, 1 )


    Author Comment

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

    Expert Comment

    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

    Threat Intelligence Starter Resources

    Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

    Join & Write a Comment

    Suggested Solutions

    This article is a continuation or rather an extension from Cascading Combos ( and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
    In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
    Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
    Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.

    729 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

    Need Help in Real-Time?

    Connect with top rated Experts

    23 Experts available now in Live!

    Get 1:1 Help Now