Mega Code Archive

 
Categories / VB.Net / Date Time
 

Compares DateTime value

Imports System.Globalization Module MainClass    Public Sub Main()                  Dim thDay As New System.DateTime(System.DateTime.Today.Year, 7, 28)                  Dim compareValue As Integer         Try            compareValue = thDay.CompareTo(System.DateTime.Today)         Catch exp As ArgumentException            System.Console.WriteLine("Value is not a DateTime")         End Try                  If compareValue < 0 Then            System.Console.WriteLine("{0:d} is in the past.", thDay)         ElseIf compareValue = 0 Then            System.Console.WriteLine("{0:d} is today!", thDay)         Else   ' compareValue >= 1             System.Console.WriteLine("{0:d} has not come yet.", thDay)         End If    End Sub End Module