VB.NET 'knows'
Date data type[
^]. It holds dates from January 1 of the year 0001 through December 31 of the year 9999, and times from 12:00:00 AM (midnight) through 11:59:59.9999999 PM.
Example 1 - using simple '=' operator:
Dim a As Date = CDate("2014-09-12"), b As Date = Date.Now
If a = b Then
Console.WriteLine("Dates are equal {0}={1}", a, b)
Else
Console.WriteLine("Dates aren't equal {0}<>{1}", a, b)
End If
Console.ReadKey()
Example 2 - using
Compare method[
^]:
Dim date1 As Date = #08/01/2009 12:00AM#
Dim date2 As Date = #08/01/2009 12:00PM#
Dim result As Integer = DateTime.Compare(date1, date2)
Dim relationship As String
If result < 0 Then
relationship = "is earlier than"
ElseIf result = 0 Then
relationship = "is the same time as"
Else
relationship = "is later than"
End If
Console.WriteLine("{0} {1} {2}", date1, relationship, date2)
Example 3 - using
DateDiff function[
^]:
Dim firstDate, msg As String
Dim secondDate As Date
firstDate = InputBox("Enter a date")
Try
secondDate = CDate(firstDate)
msg = "Days from today: " & DateDiff(DateInterval.Day, Now, secondDate)
MsgBox(msg)
Catch
MsgBox("Not a valid date value.")
End Try
Note: As is explained here:
Data Type Summary (Visual Basic)[
^], Date data type uses DateTime structure - to put it simply.