Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need to "round time"

Status
Not open for further replies.

NewTeki

Technical User
Jul 16, 2003
22
US
I need to overwrite start and stop times with even hours:
for example, if time entered is >7:53 and <8:07 I need to make it 8:00. Does anyone have a routine to handle this?

Thanks n advance for any aid you can give.
 
perhaps this is &quot;overkill&quot; for your specific purpose, on the other hand, it provides some additional flexibility:


Code:
Public Function basRndTime(dtTimeIn As Date, _
                           Optional rndIntvl As String = &quot;n&quot;, _
                           Optional rndIncr As Long = 30, _
                           Optional rndUp As Boolean = True)

    'Michael Red    2/26/04
    'Interval (rndIntvl) corresponds to an arument for DateAdd
    'Increment (rndIncr) corresponds to the # units for DateAdd
    'Direction (rndUp) is a flag to indicate the function should _
     round the value &quot;up&quot; (increase to the interval, whiich is the _
     default) or to round the value &quot;Down&quot; - e.g. Subtract from the value)

    Dim MyDiff As Long
    Dim MyIncr As Long

    MyDiff = (Format(dtTimeIn, rndIntvl) Mod rndIncr)

    If (Sgn(rndUp) <> 0) Then
        basRndTime = DateAdd(rndIntvl, rndIncr - MyDiff, dtTimeIn)
     Else
        basRndTime = DateAdd(rndIntvl, -MyDiff, dtTimeIn)
    End If

End Function





MichaelRed
m.red@att.net

Searching for employment in all the wrong places
 
Michael,

Thank you, let me play with this.


Jim
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top