Results 1 to 5 of 5

Thread: Convert to minutes

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Dec 2003
    Posts
    509

    Convert to minutes

    A timer has been stopped at some point. The timer is in the form of 00:00:00-hrs mins, secs

    how is it possible to take all of this, even if it has 10:14:29, and convert it to minutes?

    i dont mind if it has something like 117.67 mins-thats even better.

    can anyone help?

  2. #2
    Frenzied Member Mike Hildner's Avatar
    Join Date
    Jul 2002
    Location
    Des Moines, NM
    Posts
    1,690
    Seems like I'm on a TimeSpan kick these days - there are probably several ways to achieve the same results.

    VB Code:
    1. Dim span As New TimeSpan(Date.Parse("10:14:29", System.Globalization.CultureInfo.CurrentCulture, Globalization.DateTimeStyles.NoCurrentDateDefault).Ticks)
    2.         MsgBox(span.TotalMinutes)

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Dec 2003
    Posts
    509
    i get an error. i have changed it as u will notice to read the label(lblduration). it comes up with an error.

    i am attempting to read the label box value after the timer has been stopped.


    Private Sub CmdStopTimer_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CmdStopTimer.Click

    Timer1.Stop()
    Dim span As New TimeSpan(Date.Parse(lblduration.ToString, System.Globalization.CultureInfo.CurrentCulture, Globalization.DateTimeStyles.NoCurrentDateDefault).Ticks)
    MsgBox(span.TotalMinutes)

    CmdStopTimer.Enabled = False
    CmdStartTimer.Enabled = True
    End Sub

  4. #4
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    Shouldn't that be lblduration.Text.ToString? Also you can parse directly to the TimeSpan object but I believe it must have all 3 sections of time (hours:minutes:milliseconds), not for sure though.
    VB Code:
    1. Dim span As TimeSpan=TimeSpan.Parse(lblDuration.Text)
    2. Msgbox(span.TotalMinutes)

  5. #5
    Frenzied Member Mike Hildner's Avatar
    Join Date
    Jul 2002
    Location
    Des Moines, NM
    Posts
    1,690
    Edneeis is right, although it's overkill to do a ...Text.ToString. Check out what gets returned from:

    VB Code:
    1. MsgBox(lblDuration.ToString)
    2.         MsgBox(lblDuration.Text)
    3.         MsgBox(lblDuration.Text.ToString)

    And yeah, you should parse directly to a TimeSpan rather than use the date business - it's way less verbose. That was bad on my part.

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