VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



A Compare Time Function (like you can compare dates in VB)

by Proxy Avoidance (2 Submissions)
Category: String Manipulation
Difficulty: Beginner
Date Added: Wed 3rd February 2021
Rating: (3 Votes)

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.

Rate A Compare Time Function (like you can compare dates in VB)

' This is the sort of code that makes you think 'Why didnt I think of that?!?
'
' EG:
' IF TimeNo("21:55:32") < TimeNo("20:40:12") Then
' msgbox "WHOOO!"
' end if
'
' The code is also cross-compatible with different time formats...
'
' 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

Download this snippet    Add to My Saved Code

A Compare Time Function (like you can compare dates in VB) Comments

No comments have been posted about A Compare Time Function (like you can compare dates in VB). Why not be the first to post a comment about A Compare Time Function (like you can compare dates in VB).

Post your comment

Subject:
Message:
0/1000 characters