ARTICLE
Find difference between two times in VB.NET
The attached code snippet shows how to get the difference between two times in VB.NET
Hi friends, here I've included the code to compare 2 times, it's a very easy and useful code.
I'he created a function called Diff.
Private
Function Diff(ByVal H1 As String, ByVal H2 As String) As String Dim he1 As Integer : Dim mn1 As Integer Dim he2 As Integer : Dim mn2 As Integer
Dim DF As Integer Dim s he1 = Mid(H1, 1, 2) : mn1 = Mid(H1, 4, 2)
he2 = Mid(H2, 1, 2) : mn2 = Mid(H2, 4, 2)
'-diff en min---------- DF = ((he1 * 60) + mn1) - ((he2 * 60) + mn2)
'AP2.Text = DF s = Format((DF \ 60),
"00") & Format((DF Mod 60), "00") Return s End Function
You can call this function by:
var = Diff(H1,H2).
Enjoy.