quarter hours

teiben

Registered User.
Local time
Today, 20:53
Joined
Jun 20, 2002
Messages
462
HOw does one make value entered round to the nearerst quarter hour
 
Date Math

Define a form with two text boxes on it: tbxD and tbxOut.

Put the following th tbxD's AfterUpdate event:

Code:
Dim dDate As Double
dDate = CDbl(tbxD)                      'Convert date/time to Double
dDate = CDbl(CInt(dDate * 96)) / 96     'Take the integer part of the number of
                                        '15-minute intervals in a day to round
Me.tbxOut = CDate(dDate)                'Convert back to date

Enter a valid time in tbxD and the rounded time will appear in tbxOut.

Jim
 
Jim -

That's a really novel approach.

Was all set to provide another solution when I realized
yours was better. After playing with it for a while,
found that it could be easily reduced to a small function, e.g.
Code:
Function RoundTime(pTime As Variant) As Date
Dim tHold As Date
   'allows user to input either a valid time or a string
   thold = TimeValue(pTime)
   RoundTime = CDate(CDbl(CInt(CDbl(thold) * 96)) / 96)
End Function

Thanks for that--it's a keeper.

Bob
 
Bob-

Your function is simple and compact. I wanted to show what I was doing. It's the dormant teacher in me, I guess.

Cheers!
Jim
 
how do I implement?

I created the function.

I'm using the hours textbox on gotfocus to run it.

I've tried roundtime()
=roundtime()
and various other combination and nothing is working, I don't get it
 

Users who are viewing this thread

Back
Top Bottom