|
-
Jul 18th, 2004, 07:23 PM
#1
Thread Starter
Hyperactive Member
Time Diff
Hi, using this code I can compute the minutes used;
'declaring variables
Dim tim1 As DateTime
Dim tim2 As DateTime
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
tim1 = TimeOfDay ' current time
TextBox1.Text = tim1
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
tim2 = TimeOfDay ' current time
TextBox2.Text = tim2
TextBox3.Text = Int((tim2.Subtract(tim1)).TotalMinutes)
End Sub
But is there a way to computer both hour(s) and minutes used?
-
Jul 18th, 2004, 08:23 PM
#2
Addicted Member
VB Code:
'Declarations
Private tim1 As DateTime
Private tim2 As DateTime
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
tim1 = Now() ' current time
TextBox1.Text = tim1.ToString
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim timeDifference As TimeSpan
tim2 = Now() ' current time
'Get the difference between the 2 times
timeDifference = tim2.Subtract(tim1)
TextBox2.Text = tim2.ToString
'Display the difference
TextBox3.Text = "Hours : " & timeDifference.Hours.ToString & vbCrLf & "Minutes: " & timeDifference.Minutes.ToString
End Sub
You can get other information about the difference in times from the timespan properties.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|