Decode Unusual Timespan

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Charles Law

    Decode Unusual Timespan

    I have a 'timespan' which is specified in an unusual way. For example, to
    specify 47 hours and 26 minutes, the timepsan is specified as

    47:26

    If I use Timespen.TryPar se on this then, of course, it fails. Can anyone
    think of a neat way to decode timespans specified in this way? I also have
    timespans specified as

    3.30

    which would mean 3hrs and 30 minutes.

    I realise that I could split the values and format my own timespan, but I am
    wondering if there is a one-liner built-in.

    TIA

    Charles


  • Patrice

    #2
    Re: Decode Unusual Timespan

    Then create a function and reuse at will ? It could give something such as
    (checking code left out) :

    Shared Function ToTimeSpan(ByVa l s As String, Optional ByVal sep As Char
    = ":"c) As TimeSpan
    Dim v() As String
    v = s.Split(sep)
    Dim t As New TimeSpan(CInt(v (0)), CInt(v(1)), 0)
    Return t
    End Function

    Shared Sub Main()
    MsgBox(ToTimeSp an("47:26").ToS tring)
    MsgBox(ToTimeSp an("3.30", "."c).ToStr ing)
    End Sub

    --
    Patrice

    "Charles Law" <blank@nowhere. coma écrit dans le message de groupe de
    discussion : e4zh70EGJHA.493 6@TK2MSFTNGP03. phx.gbl...
    I have a 'timespan' which is specified in an unusual way. For example, to
    specify 47 hours and 26 minutes, the timepsan is specified as
    >
    47:26
    >
    If I use Timespen.TryPar se on this then, of course, it fails. Can anyone
    think of a neat way to decode timespans specified in this way? I also have
    timespans specified as
    >
    3.30
    >
    which would mean 3hrs and 30 minutes.
    >
    I realise that I could split the values and format my own timespan, but I
    am wondering if there is a one-liner built-in.
    >
    TIA
    >
    Charles
    >
    >

    Comment

    • Charles Law

      #3
      Re: Decode Unusual Timespan

      Hi Patrice

      Thanks for the reply. From that I read that there is no one-liner, so I am
      stuck with rolling my own, as you say.

      Cheers

      Charles


      "Patrice" <http://www.chez.com/scribe/wrote in message
      news:OrWG3wJGJH A.5944@TK2MSFTN GP03.phx.gbl...
      Then create a function and reuse at will ? It could give something such as
      (checking code left out) :
      >
      Shared Function ToTimeSpan(ByVa l s As String, Optional ByVal sep As
      Char = ":"c) As TimeSpan
      Dim v() As String
      v = s.Split(sep)
      Dim t As New TimeSpan(CInt(v (0)), CInt(v(1)), 0)
      Return t
      End Function
      >
      Shared Sub Main()
      MsgBox(ToTimeSp an("47:26").ToS tring)
      MsgBox(ToTimeSp an("3.30", "."c).ToStr ing)
      End Sub
      >
      --
      Patrice
      >
      "Charles Law" <blank@nowhere. coma écrit dans le message de groupe de
      discussion : e4zh70EGJHA.493 6@TK2MSFTNGP03. phx.gbl...
      >I have a 'timespan' which is specified in an unusual way. For example, to
      >specify 47 hours and 26 minutes, the timepsan is specified as
      >>
      >47:26
      >>
      >If I use Timespen.TryPar se on this then, of course, it fails. Can anyone
      >think of a neat way to decode timespans specified in this way? I also
      >have timespans specified as
      >>
      >3.30
      >>
      >which would mean 3hrs and 30 minutes.
      >>
      >I realise that I could split the values and format my own timespan, but I
      >am wondering if there is a one-liner built-in.
      >>
      >TIA
      >>
      >Charles
      >>
      >>
      >

      Comment

      Working...