ARTICLE

Find difference between two times in VB.NET

Posted by ahmed fellah Articles | VB.NET How do I August 07, 2009
The attached code snippet shows how to get the difference between two times in VB.NET
 
Reader Level:

 

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.

 

Login to add your contents and source code to this article
Article Extensions
Contents added by roma naveen on Aug 10, 2009

hello iam student

so i want learned Vb.net

 

share this article :
post comment
 
Become a Sponsor
PREMIUM SPONSORS
  • ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications. Visit DynamicPDF here
    The leading .NET charting control now features PDF, Flash and Silverlight export, visualization of large datasets and more. Deliver true charting functionality to your BI, Scorecard, Presentation or Scientific apps. Download evaluation now.
Team Foundation Server Hosting
Become a Sponsor