How to Get the Time Span of Two Dates in VB.Net

The program will teach you how to get the date and time span of two different dates, You need two DateTimePicker, Four Labels and one Command button.

The Output:


Code:
Public Class frmTimespan
    Private Sub btnFind_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFind.Click
        Dim date1 As Date
        Dim date2 As Date
        Dim diff As TimeSpan
        date1 = Convert.ToDateTime(DateTimePicker1.Value)
        date2 = Convert.ToDateTime(DateTimePicker2.Value)
        diff = date2.Subtract(date1)
        Label1.Text = "Total Days: " & FormatNumber(diff.TotalDays, 0)
        Label2.Text = "Total Hours: " & FormatNumber(diff.TotalHours, 0)
        Label3.Text = "Total Minutes: " & FormatNumber(diff.TotalMinutes, 0)
        Label4.Text = "Total Second: " & FormatNumber(diff.TotalSeconds, 0)
    End Sub
End Class
How to Get the Time Span of Two Dates in VB.Net How to Get the Time Span of Two Dates in VB.Net Reviewed by code-dev on 11:50 AM Rating: 5

No comments:

Powered by Blogger.