Calculating elapsed time

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Pachalo
    New Member
    • Sep 2008
    • 3

    #1

    Calculating elapsed time

    Morning...

    Am working on a simple billing system and a looking for a code that can help calculate the difference in time between sessions..(am using VB.Net )

    This is what is happening:

    l have a :
    combobox named combobox1
    textbox named txttotalamount
    btnStart
    Timer 1
    btnEnd

    Under btnStart l have the following code:
    Code:
    Me.Timer1.Start()
                Me.Timer1.Start()
                Me.Timer1.Enabled = True
    and under btnEnd l have the following code:
    Code:
            Me.Timer1.Stop()
            Me.txtTotaltime.Text = m_seconds.ToString()
            Dim number1 As Integer
            Dim number2 As Integer
            Dim answer As Integer
            number1 = txtTotaltime.Text
            number2 = ComboBox1.Items.Count
            answer = number1 * number2
            MsgBox(answer)
    What l want is that l should be able to use the system time..if the system time is 12:01 that should be my start time and my end time should also be taken from the system..the counting should be in minutes..please help me
    Last edited by Frinavale; Apr 6 '09, 06:54 PM. Reason: Added [code] tags. Please post code in [code] [/code] tags.
  • jg007
    Contributor
    • Mar 2008
    • 283

    #2
    depending on what you are trying to do you might find it easier to use the ' stopwatch ' class

    Comment

    • jg007
      Contributor
      • Mar 2008
      • 283

      #3
      you can also do subtract one date value from another to return a timespan value and then extract the minutes

      Code:
       elapsed = TimeEnd - TimeStart
      
       totalmin = elapsed.TotalMinutes

      Comment

      • puremelon
        New Member
        • Apr 2009
        • 1

        #4
        Timespan that goes to next date showing negative value.

        I have a web app that post response time between a start and stop time I am using timespan and when the interval goes to the next date it shows an incorrect negative value. Also I am only displaying whole numbers rounded to nearest minute.

        Can anyone help with times that surpass midnight and go into next day? Any help Appreciated.
        ''StartDatetime and StopDateTime difference is written to me.alarmlocid.t ext (#) removes the .000etc

        Code:
        Dim dteStartDateTime As Date = CDate(Me.StartDateTime().Text)
        Dim dteStopDateTime As Date = CDate(Me.StopDateTime().Text)
        Dim tsTimeSpan As Timespan
        Dim iTotalTime As Double
        
        tsTimeSpan = dteStopDateTime.Subtract(dteStartDateTime)
         
        iTotalTime = tsTimeSpan.TotalMinutes
        
        Me.AlarmLocId.Text = iTotalTime.ToString("#")
        Last edited by Frinavale; Apr 6 '09, 06:55 PM. Reason: Added [code] tags. Please post code in [code] [/code] tags.

        Comment

        • Plater
          Recognized Expert Expert
          • Apr 2007
          • 7872

          #5
          I have never had an issue with TimeSpans not being able to handle going on to the next day.
          I would think it has something to do with using the wrong objects. You should be using DateTime objects, not Date objects.
          What values are in Me.StartDateTim e().Text and Me.StopDateTime ().Text exactly?
          Does CDate provide the same functionality as the .NET equiv of DateTime.Parse( ) ?

          Comment

          Working...