ADVERTISEMENT
ADVERTISEMENT

VB.Net program to demonstrate the Equals() method of DateTime class

Here, we are going to demonstrate the Equals() method of DateTime class in VB.Net.
Submitted by Nidhi, on January 21, 2021

The Equals() method is used to compare two date objects and returns a boolean value to specify the result of comparison.

Syntax:

Function Equals(ByVal date1 as Date, ByVal date2 as Date) as Boolean

Parameters:

  • Date1 : First specified date object.
  • Date2 : Second specified date object.

Return Value: It returns True when two objects of the DateTime class are equal otherwise it returns False.

Program/Source Code:

The source code to demonstrate the Equals() method of the DateTime class is given below. The given program is compiled and executed successfully.

'VB.NET program to demonstrate Equals() method of DateTime class.

Imports System

Module Module1
    Sub Main()
        Dim date1 As New DateTime(2020, 4, 27)
        Dim date2 As New DateTime(2021, 3, 28)
        Dim date3 As New DateTime(2021, 3, 28)
        Dim ret As Boolean = False

        ret = DateTime.Equals(date1, date2)
        If (ret = True) Then
            Console.WriteLine("{0} and {1} are equal", date1, date2)
        Else
            Console.WriteLine("{0} and {1} are not equal", date1, date2)
        End If

        ret = DateTime.Equals(date2, date3)
        If (ret = True) Then
            Console.WriteLine("{0} and {1} are equal", date2, date3)
        Else
            Console.WriteLine("{0} and {1} are not equal", date2, date3)
        End If
    End Sub
End Module

Output:

27-04-2020 00:00:00 and 28-03-2021 00:00:00 are not equal
28-03-2021 00:00:00 and 28-03-2021 00:00:00 are equal
Press any key to continue . . .

Explanation:

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 three objects of the DateTime class that are initialized with date values. Then we compared date objects using the Equals() method of the DateTime class and print the appropriate message on the console screen.

VB.Net Date & Time Programs »



ADVERTISEMENT



ADVERTISEMENT



Comments and Discussions


ADVERTISEMENT

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

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

© https://www.includehelp.com some rights reserved.