VB date compare

In VB.NET, you can compare different date values by using the Compare(date1,date2) function of the Date type. The function return 0 if both dates are equal. It returns -1 if date1 is less than date2. If the date1 is greater than date2, it returns 1.
Module Module1

   Sub Main()
     Dim dat1 = Date.Parse("09-02-2011")
     Dim dat2 = Date.Parse("09-02-2012")
     If Date.Compare(dat1, dat2) = 0 Then
        Console.WriteLine("Both dates are equal.")
     ElseIf Date.Compare(dat1, dat2) = -1 Then
        Console.WriteLine("{0} is less than {1}.", dat1, dat2)
        Console.WriteLine("{0} is greater than {1}.", dat1, dat2)
     End If


   End Sub
End Module

Posted by: Narin | post date: 02-18-2013 | Subject: VB.NET Programming Language

This website intents to provide free and high quality tutorials, examples, exercises and solutions, questions and answers of programming and scripting languages:
C, C++, C#, Java, VB.NET, Python, VBA,PHP & Mysql, SQL, JSP, ASP.NET,HTML, CSS, JQuery, JavaScript and other applications such as MS Excel, MS Access, and MS Word. However, we don't guarantee all things of the web are accurate. If you find any error, please report it then we will take actions to correct it as soon as possible.