This will allow you to compare times.

By | 2019-12-30

I noticed that there is a ‘Date’ type in VB, but no ‘Time’ type. So if you want to compare Dates you are fine, but for Time comparisons you are a bit stuffed. This is very simple and will allow you to convert times into numbers so that you can make easy comparisons with them.

Example

IF TimeNo("21:55:32") < TimeNo("20:40:12") Then
   msgbox "WHOOO!"
end if

IF TimeNo("21:55:32") < TimeNo("8:40PM") Then
   msgbox "WHOOO!"
end if

Function

Public Function TimeNo(Time As String) As Long
TimeNo = CLng(Replace(Format(Time, "hhnnss"), ":", ""))
End Function

Author: dwirch

Derek Wirch is a seasoned IT professional with an impressive career dating back to 1986. He brings a wealth of knowledge and hands-on experience that is invaluable to those embarking on their journey in the tech industry.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.