VB.Net program to print the sum of two times

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

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 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


Days: 429
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 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!


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.