Rounding time

  • Thread starter Thread starter Kamyk
  • Start date Start date
K

Kamyk

Hell all!

How to round a time into 15 minutes period for example

--------------------------
Now is: | After rounding
--------------------------
19:00 | 19:15
19:05 | 19:15
19:12 | 19:15
19:16 | 19:30
19:30 | 19:45
19:36 | 19:45
19:45 | 20:00
20:00 | 20:15

Is it possible to do it by easy way?

Thank you in advance
Marcin
 
Marcin,

Here is one way to do what you want to do:

Place the following function in the module for your form:
Function RoundTime(varTime As Variant) As String
Dim varMinutes As String, varHours As String
varHours = Format(varTime, "hh")
varMinutes = Format(varTime, "nn")
If varMinutes <= 15 Then
varMinutes = "00"
ElseIf varMinutes <= "30" Then
varMinutes = "30"
ElseIf varMinutes <= "45" Then
varMinutes = "45"
Else
varMinutes = "00"
varHours = Str(Val(varHours) + 1)
End If
RoundTime = varHours & ":" & varMinutes
End Function

Then in the AfterUpdate event of your text box where the
time will be entered, place the following code:

Me.NameOfCtrl = RoundTime(Me.NameOfCtrl)

I am assuming that you have the format of the text box
set to Short Time with an input mask of "00:00;0;_"

When you type in the time and then exit the field, the
function will round the time.

HTH
Byron
 
Back
Top