Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.
Function dhRoundTime(dtmTime As Date, intInterval As Integer) As Date ' Round the time value in varTime to the nearest minute ' interval in intInterval Dim intTime As Integer Dim sglTime As Single Dim intHour As Integer Dim intMinute As Integer Dim lngdate As Long ' Get the date portion of the date/time value lngdate = DateValue(dtmTime) ' Get the time portion as a number like 11.5 for 11:30. sglTime = TimeValue(dtmTime) * 24 ' Get the hour and store it away. Int truncates, ' CInt rounds, so use Int. intHour = Int(sglTime) ' Get the number of minutes, and then round to the nearest ' occurrence of the interval specified. intMinute = CInt((sglTime - intHour) * 60) intMinute = CInt(intMinute / intInterval) * intInterval ' Build back up the original date/time value, ' rounded to the nearest interval. dhRoundTime = CDate(lngdate + ((intHour + intMinute / 60) / 24)) End Function