Turn "200" into "3h 20m"

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

    Turn "200" into "3h 20m"

    Greetings,

    I am attempting to take a number that is currently in minutes and turn it
    into a string that will list the hours followed by minutes.

    Some more examples:

    "30" into "0h 30m"
    "155 into "2h 35m"
    "180 into "3h 0m"

    Is this possible? How can I do it? Thanks,

    -Dave


  • Phil Hunt

    #2
    Re: Turn "200&qu ot; into "3h 20m"

    Dave,

    Dim Hours As Integer = 0 ' Always start at 0 hours
    Dim Minutes As Integer = 155 ' # of minutes to convert from

    Do While Minutes >= 60
    Hours += 1
    Minutes -= 60
    Loop

    Return Hours & "h " & Minutes & "m"

    Phil

    "Dave" <nospam@yahoo.c om> wrote in message
    news:euY$YFk$EH A.3908@TK2MSFTN GP12.phx.gbl...[color=blue]
    > Greetings,
    >
    > I am attempting to take a number that is currently in minutes and turn it
    > into a string that will list the hours followed by minutes.
    >
    > Some more examples:
    >
    > "30" into "0h 30m"
    > "155 into "2h 35m"
    > "180 into "3h 0m"
    >
    > Is this possible? How can I do it? Thanks,
    >
    > -Dave
    >[/color]


    Comment

    • md

      #3
      Re: Turn &quot;200&qu ot; into &quot;3h 20m&quot;

      Minutes \ 60 to get hours
      Minutes MOD 60 gets you the remaining minutes

      Hours & "h " & minutes & "m"

      Matt

      "Dave" <nospam@yahoo.c om> wrote in message
      news:euY$YFk$EH A.3908@TK2MSFTN GP12.phx.gbl...[color=blue]
      > Greetings,
      >
      > I am attempting to take a number that is currently in minutes and turn it
      > into a string that will list the hours followed by minutes.
      >
      > Some more examples:
      >
      > "30" into "0h 30m"
      > "155 into "2h 35m"
      > "180 into "3h 0m"
      >
      > Is this possible? How can I do it? Thanks,
      >
      > -Dave
      >
      >[/color]


      Comment

      • Chris, Master of All Things Insignificant

        #4
        Re: Turn &quot;200&qu ot; into &quot;3h 20m&quot;

        Dim StartingMinutes As Integer = 155

        Dim DT As New TimeSpan(0, StartingMinutes , 0)

        MessageBox.Show (DT.Hours & "h" & " " & DT.Minutes & "m")

        Hope it helps
        Chris


        "Dave" <nospam@yahoo.c om> wrote in message
        news:euY$YFk$EH A.3908@TK2MSFTN GP12.phx.gbl...[color=blue]
        > Greetings,
        >
        > I am attempting to take a number that is currently in minutes and turn it
        > into a string that will list the hours followed by minutes.
        >
        > Some more examples:
        >
        > "30" into "0h 30m"
        > "155 into "2h 35m"
        > "180 into "3h 0m"
        >
        > Is this possible? How can I do it? Thanks,
        >
        > -Dave
        >[/color]


        Comment

        • Phil Hunt

          #5
          Re: Turn &quot;200&qu ot; into &quot;3h 20m&quot;

          Scratch that.

          I haven't worked with TimeSpan in .NET, and so my solution stinks.

          Chris' solution is much better.

          "Phil Hunt" <j.philip.hunt@ gmail.com> wrote in message
          news:%23dw$oJk$ EHA.2104@TK2MSF TNGP14.phx.gbl. ..[color=blue]
          > Dave,
          >
          > Dim Hours As Integer = 0 ' Always start at 0 hours
          > Dim Minutes As Integer = 155 ' # of minutes to convert from
          >
          > Do While Minutes >= 60
          > Hours += 1
          > Minutes -= 60
          > Loop
          >
          > Return Hours & "h " & Minutes & "m"
          >
          > Phil
          >
          > "Dave" <nospam@yahoo.c om> wrote in message
          > news:euY$YFk$EH A.3908@TK2MSFTN GP12.phx.gbl...[color=green]
          >> Greetings,
          >>
          >> I am attempting to take a number that is currently in minutes and turn it
          >> into a string that will list the hours followed by minutes.
          >>
          >> Some more examples:
          >>
          >> "30" into "0h 30m"
          >> "155 into "2h 35m"
          >> "180 into "3h 0m"
          >>
          >> Is this possible? How can I do it? Thanks,
          >>
          >> -Dave
          >>[/color]
          >
          >[/color]


          Comment

          • Dave

            #6
            Re: Turn &quot;200&qu ot; into &quot;3h 20m&quot;

            Great! Three ways to do it. Thanks for all the help.

            "Dave" <nospam@yahoo.c om> wrote in message
            news:euY$YFk$EH A.3908@TK2MSFTN GP12.phx.gbl...[color=blue]
            > Greetings,
            >
            > I am attempting to take a number that is currently in minutes and turn it
            > into a string that will list the hours followed by minutes.
            >
            > Some more examples:
            >
            > "30" into "0h 30m"
            > "155 into "2h 35m"
            > "180 into "3h 0m"
            >
            > Is this possible? How can I do it? Thanks,
            >
            > -Dave
            >[/color]


            Comment

            • Jay B. Harlow [MVP - Outlook]

              #7
              Re: Turn &quot;200&qu ot; into &quot;3h 20m&quot;

              Chris & Dave,
              You can also use TimeSpan.FromMi nutes:

              Dim ts As TimeSpan = TimeSpan.FromMi nutes(StartingM inutes)

              There are also FromDays, FromHours, FromMillisecond s, FromSeconds &
              FromTicks.

              I find the above From* methods to be a little more explicit on what is being
              converted, rather then trying to remember if the 3 parameter constructor is
              "days, hours, minutes" or "hours, minutes, seconds"... Otherwise the result
              is the same!

              The cool thing (more important thing?) about the From* methods is they take
              a Double, so you can say:

              Dim ts As TimeSpan = TimeSpan.FromHo urs(1.5)

              NOTE: FromTicks take a Long as a fraction of a Tick doesn't specifically
              make sense...

              Hope this helps
              Jay

              "Chris, Master of All Things Insignificant" <chris@No_Spam_ Please.com> wrote
              in message news:uKYf5Mk$EH A.1408@TK2MSFTN GP10.phx.gbl...[color=blue]
              > Dim StartingMinutes As Integer = 155
              >
              > Dim DT As New TimeSpan(0, StartingMinutes , 0)
              >
              > MessageBox.Show (DT.Hours & "h" & " " & DT.Minutes & "m")
              >
              > Hope it helps
              > Chris
              >
              >
              > "Dave" <nospam@yahoo.c om> wrote in message
              > news:euY$YFk$EH A.3908@TK2MSFTN GP12.phx.gbl...[color=green]
              >> Greetings,
              >>
              >> I am attempting to take a number that is currently in minutes and turn it
              >> into a string that will list the hours followed by minutes.
              >>
              >> Some more examples:
              >>
              >> "30" into "0h 30m"
              >> "155 into "2h 35m"
              >> "180 into "3h 0m"
              >>
              >> Is this possible? How can I do it? Thanks,
              >>
              >> -Dave
              >>[/color]
              >
              >[/color]


              Comment

              • Chris, Master of All Things Insignificant

                #8
                Re: Turn &quot;200&qu ot; into &quot;3h 20m&quot;

                Good point, never looked at those methods before.

                So many methods so little time.
                Chris

                "Jay B. Harlow [MVP - Outlook]" <Jay_Harlow_MVP @msn.com> wrote in message
                news:uhhnRVl$EH A.2788@TK2MSFTN GP15.phx.gbl...[color=blue]
                > Chris & Dave,
                > You can also use TimeSpan.FromMi nutes:
                >
                > Dim ts As TimeSpan = TimeSpan.FromMi nutes(StartingM inutes)
                >
                > There are also FromDays, FromHours, FromMillisecond s, FromSeconds &
                > FromTicks.
                >
                > I find the above From* methods to be a little more explicit on what is
                > being converted, rather then trying to remember if the 3 parameter
                > constructor is "days, hours, minutes" or "hours, minutes, seconds"...
                > Otherwise the result is the same!
                >
                > The cool thing (more important thing?) about the From* methods is they
                > take a Double, so you can say:
                >
                > Dim ts As TimeSpan = TimeSpan.FromHo urs(1.5)
                >
                > NOTE: FromTicks take a Long as a fraction of a Tick doesn't specifically
                > make sense...
                >
                > Hope this helps
                > Jay
                >
                > "Chris, Master of All Things Insignificant" <chris@No_Spam_ Please.com>
                > wrote in message news:uKYf5Mk$EH A.1408@TK2MSFTN GP10.phx.gbl...[color=green]
                >> Dim StartingMinutes As Integer = 155
                >>
                >> Dim DT As New TimeSpan(0, StartingMinutes , 0)
                >>
                >> MessageBox.Show (DT.Hours & "h" & " " & DT.Minutes & "m")
                >>
                >> Hope it helps
                >> Chris
                >>
                >>
                >> "Dave" <nospam@yahoo.c om> wrote in message
                >> news:euY$YFk$EH A.3908@TK2MSFTN GP12.phx.gbl...[color=darkred]
                >>> Greetings,
                >>>
                >>> I am attempting to take a number that is currently in minutes and turn
                >>> it into a string that will list the hours followed by minutes.
                >>>
                >>> Some more examples:
                >>>
                >>> "30" into "0h 30m"
                >>> "155 into "2h 35m"
                >>> "180 into "3h 0m"
                >>>
                >>> Is this possible? How can I do it? Thanks,
                >>>
                >>> -Dave
                >>>[/color]
                >>
                >>[/color]
                >
                >[/color]


                Comment

                Working...