RoundMinutes

Rounds time into nearest quarter up or down, half up or down based on argument passed.
Accepts and returns time as string in format of HH:MM
RoundType can be one of below
1 : shift the minutes up to quarters
2 : shift the minutes down to quarters
3 : shift the minutes to quarters up or down depend upon the minutes no
4 : shift the minutes up to halves
5 : shift the minutes down to halves
6 : shift the minutes to halves up or down depend upon the minutes no

Might need some testing

Function RoundMinutes(RoundType, InputHourMinute)
 ' Returns the Hour:Minute after rounding input
 ' Input string expected to be in HH:MM
 ' InputHourMinute  : the hour:minute
 ' RoundType    : then identifier
 ' 1 : shift the minutes up to quarters
 ' 2 : shift the minutes down to quarters
 ' 3 : shift the minutes to quarters up or down depend upon the minutes no
 ' 4 : shift the minutes up to halves
 ' 5 : shift the minutes down to halves
 ' 6 : shift the minutes to halves up or down depend upon the minutes no

 HourNo     = CInt(Left(InputHourMinute, instr(1, InputHourMinute, ":")-1))
 MinuteNo     = CInt(Mid(InputHourMinute, instr(1, InputHourMinute, ":")+1, 500))
 Select Case RoundType
 Case 1 ' Quarters up
  If MinuteNo - 15 < 0 Then MinuteNo = 15
  If MinuteNo > 15 And MinuteNo < 30 Then MinuteNo = 30
  If MinuteNo > 30 And MinuteNo < 45 Then MinuteNo = 45
  If MinuteNo > 45 Then MinuteNo = 0: HourNo = HourNo + 1
 Case 2 ' Quarters down
  If MinuteNo - 15 < 0 Then MinuteNo = 0
  If MinuteNo >= 15 And MinuteNo < 30 Then MinuteNo = 15
  If MinuteNo >= 30 And MinuteNo < 45 Then MinuteNo = 30
  If MinuteNo >= 45 Then MinuteNo = 45
 Case 3 ' Quarters manage
  If MinuteNo < 8 Then
   MinuteNo = 0
  ElseIf (MinuteNo >= 8 And MinuteNo <= 15) Or (MinuteNo > 15 And MinuteNo < 23) Then
   MinuteNo = 15
  ElseIf (MinuteNo >= 23 And MinuteNo <= 30) Or (MinuteNo > 30 And MinuteNo < 38) Then
   MinuteNo = 30
  ElseIf (MinuteNo >= 38 And MinuteNo <= 45) Or (MinuteNo > 45 And MinuteNo < 53) Then
   MinuteNo = 45
  ElseIf MinuteNo >= 53 Then
   MinuteNo = 0
   HourNo = HourNo + 1
  End If
 Case 4 ' halves up
  If MinuteNo > 0 And MinuteNo < 30 Then
   MinuteNo = 30
  ElseIf MinuteNo > 30 And MinuteNo <= 59 Then
   MinuteNo = 0
   HourNo = HourNo + 1
  End If
 Case 5 ' halves down
  If MinuteNo < 30 Then
   MinuteNo = 0
  ElseIf MinuteNo > 30 And MinuteNo <= 59 Then
   MinuteNo = 30
  End If
 Case 6 ' halves manage
  If MinuteNo <= 15 Then
   MinuteNo = 0
  ElseIf MinuteNo > 15 And MinuteNo < 30 Then
   MinuteNo = 30
  ElseIf MinuteNo > 30 And MinuteNo <= 45 Then
   MinuteNo = 30
  ElseIf MinuteNo > 45 Then
   MinuteNo = 0
   HourNo = HourNo + 1
  End If
 End Select
 RoundMinutes   = HourNo & ":" & MinuteNo
End Function

RoundType, InputHourMinute

Views 89 Downloads 36

'time', 'convert', 'replace', 'round', 'roundup', 'rounddown', 'floor', 'ceiling', 'hh','mm', 'format', 'NotTested'

ANmarAmdeen
397
Attachments
Date+Time Classic ASP
Revisions

v1.0