VB.Net program to compare two dates

Here, we are going to learn how to compare two dates in VB.Net?
Submitted by Nidhi, on January 19, 2021

Here, we will compare two dates and then print appropriate according to the comparation on the console screen.

Program/Source Code:

The source code to compare the two dates is given below. The given program is compiled and executed successfully.

'VB.NET program to compare two dates.

Imports System

Module Module1
    Sub Main()

        Dim date1 As New DateTime(2020, 3, 22)
        Dim date2 As New DateTime(2021, 5, 25)

        If (date1 < date2) Then
            Console.WriteLine("{0} is less than {1}", date1, date2)
            Console.WriteLine("{0} is less than {1}", date2, date1)
        End If
    End Sub
End Module


22-03-2020 00:00:00 is less than 25-05-2021 00:00:00
Press any key to continue . . .


In the above program, we created a module Module1 that contains the Main() function. The Main() function is the entry point for the program.

In the Main() function, we created two objects of the DateTime class that are initialized with date values. Then we compared both objects using less than operator and print an appropriate message on the console screen.

VB.Net Date & Time Programs »



Comments and Discussions!





Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© some rights reserved.