Results 1 to 2 of 2

Thread: Time Diff

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2002
    Location
    Pilipinas
    Posts
    441

    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?

  2. #2
    Addicted Member
    Join Date
    Aug 2003
    Posts
    153
    VB Code:
    1. 'Declarations
    2.  
    3. Private tim1 As DateTime
    4. Private tim2 As DateTime
    5.  
    6. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    7. tim1 = Now() ' current time
    8. TextBox1.Text = tim1.ToString
    9. End Sub
    10.  
    11. Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
    12. Dim timeDifference As TimeSpan
    13. tim2 = Now() ' current time
    14.  
    15. 'Get the difference between the 2 times
    16. timeDifference = tim2.Subtract(tim1)
    17.  
    18. TextBox2.Text = tim2.ToString
    19.  
    20. 'Display the difference
    21. TextBox3.Text = "Hours : " & timeDifference.Hours.ToString & vbCrLf & "Minutes: " & timeDifference.Minutes.ToString
    22.  
    23. 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
  •  



Click Here to Expand Forum to Full Width