Search Tools Links Login

Compare Time Function

Posted: 2019-12-30
By: ProxyAvoidance
Viewed: 211

Filed Under:

Visual Basic 6, Visual Basic 6, Visual Basic 6

No attachments for this post

This will allow you to compare times.

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.


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


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

Comments on this post

No comments have been added for this post.

You must be logged in to make a comment.