VB.Net program to print the sum of two dates in days

Here, we rare going to learn how to print the difference of two dates in days in VB.Net?
Submitted by Nidhi, on January 19, 2021 [Last updated : March 07, 2023]

Sum of two dates in VB.Net

Here, we will calculate the difference between two dates in days and print the result on the console screen.

Program/Source Code:

The source code to print the difference between two dates in days is given below. The given program is compiled and executed successfully.

VB.Net code to find the sum of two dates in days

'VB.NET program to print difference of two dates in days.

Imports System

Module Module1
    Sub Main()
        Dim diff As TimeSpan
        Dim date1 As New DateTime(2020, 3, 22)
        Dim date2 As New DateTime(2021, 5, 25)

        diff = date2 - date1

        Console.WriteLine("Days: {0}", diff.TotalDays)
    End Sub
End Module

Output

Days: 429
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 two objects of the DateTime class and initialized them with date values. After that, we calculated the difference between two dates in days and print the result on the console screen.

VB.Net Date & Time Programs »





Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.