Rounding time

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
 
K

K Dales

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
 
K

Kamyk

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top