Home »
VB.Net »
VB.Net Programs
VB.Net program to print the sum of two dates in days
By Nidhi Last Updated : November 16, 2024
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 »