Here is one way to round up the system time
to the nearest 5 minutes.
Private Sub Time_Test()
Dim sTime As String, newTime As String
sTime = Format(Now(), "HH:MM:SS")
newTime = Calc_NewTime(sTime)
MsgBox "System time: " & sTime & vbCrLf & _
"Minutes rounded up: " & newTime
End Sub
Function Calc_NewTime(inText As String) As String
'round up minutes to the nearest 5 minutes.
'return time in text string formatted as HH:MM:SS
Dim intMinutes As Integer, intSeconds As Integer
Dim timeText As String
intMinutes = CInt(Mid(inText, 4, 2))
intSeconds = CInt(Mid(inText, 7, 2))
If intMinutes Mod 5 <> 0 Or intSeconds <> 0 Then
intMinutes = intMinutes + (5 - (intMinutes Mod 5))
End If
timeText = Mid(inText, 1, 3) & Right("0" & CStr(intMinutes), 2) & ":00"
Calc_NewTime = timeText
End Function
Bookmarks