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
 
Function RoundTime(TimeIn As Date) As Date

Select Case Minute(TimeIn)
Case 0 To 15
RoundTime = TimeValue(Hour(TimeIn) & ":15")
Case 16 To 30
RoundTime = TimeValue(Hour(TimeIn) & ":30")
Case 31 To 45
RoundTime = TimeValue(Hour(TimeIn) & ":45")
Case Else
RoundTime = TimeValue(Hour(TimeIn) + 1 & ":00")
End Select

End Function
 
Uzytkownik "K Dales said:
Function RoundTime(TimeIn As Date) As Date

Select Case Minute(TimeIn)
Case 0 To 15
RoundTime = TimeValue(Hour(TimeIn) & ":15")
Case 16 To 30
RoundTime = TimeValue(Hour(TimeIn) & ":30")
Case 31 To 45
RoundTime = TimeValue(Hour(TimeIn) & ":45")
Case Else
RoundTime = TimeValue(Hour(TimeIn) + 1 & ":00")
End Select

End Function
Thank you. I can`t believe it how it is easy!!
Thank you again
Marcin from Poland
 
Back
Top