Sunday, May 23, 2010

Timespan Tutorial - Calculate the Date and Time Difference Between 2 Dates or Times Visual Basic {VB.net}

Hello and welcome to another cool VB.net tutorial by MrVBDude.!!!

Alright today i will be teaching u all how to calculate the time or date difference between two dates of two times.. ok so lets begin..!

REQUIREMENTS:
8 Labels (Name: Label1-Label8) (Text: StartDate, End Date, Start Time, End Time, Total Number of Days, Total Number of Hours, Total Number of Minutes, Total Number of Seconds)
2 DateTimePicker (Name: DateTimePicker1, DateTimePicker2)
8 Textbox (Name: Textbox1-Textbox8) (Text: " ")
1 Button (Name: Button1) (Text: Find Timespan (Time Difference) between 2 dates?)

Codes:

Public Class Form1

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

Dim date1 As Date
Dim date2 As Date
Dim difference As TimeSpan
date1 = Convert.ToDateTime(DateTimePicker1.Value)
date2 = Convert.ToDateTime(DateTimePicker2.Value)
difference = date2.Subtract(date1)
TextBox3.Text = FormatNumber(difference.Days, 0)
TextBox6.Text = FormatNumber(difference.TotalHours, 0)
TextBox5.Text = FormatNumber(difference.TotalMinutes, 0)
TextBox4.Text = FormatNumber(difference.TotalSeconds, 0)

End Sub

End Class
_________________________________________________________________________

Here is the video tutorial:

No comments:

Post a Comment