Results 1 to 10 of 10

Thread: [RESOLVED] Minutes to Hour & minutes

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2004
    Location
    Kolkata, India
    Posts
    290

    Resolved [RESOLVED] Minutes to Hour & minutes

    Hi

    How can I convert the total minutes into hour minutes.
    ex:
    Total minutes : 209
    I want it should display : 3 hours 29 minutes


    thanks

    asm

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Minutes to Hour & minutes

    vb.net Code:
    1. Dim time As TimeSpan = TimeSpan.FromMinutes(209)
    2.  
    3. MessageBox.Show(String.Format("{0} hours {1} minutes", _
    4.                               time.Hours, _
    5.                               time.Minutes))
    Note that that will only be correct if the total time is less than 24 hours. If you want to handle times greater than that then do this:
    vb.net Code:
    1. Dim time As TimeSpan = TimeSpan.FromMinutes(209)
    2.  
    3. MessageBox.Show(String.Format("{0} hours {1} minutes", _
    4.                               Math.Floor(time.TotalHours), _
    5.                               time.Minutes))
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2004
    Location
    Kolkata, India
    Posts
    290

    Re: Minutes to Hour & minutes

    thanks for your quick help

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2004
    Location
    Kolkata, India
    Posts
    290

    Re: Minutes to Hour & minutes

    How can I display the total minutes - get from textbox1
    display in textbox2 with hour minutes

    vb Code:
    1. Dim TotalMinutes As Double
    2.         TotalMinutes = Val(TextBox1.Text)
    3.         Dim ShowTime As TimeSpan = TimeSpan.FromMinutes(TotalMinutes)
    4.         TextBox2.Text = ShowTime.Hours + ShowTime.Minutes
    5.         MessageBox.Show(String.Format("{0} hours {1} minutes", ShowTime.Hours, ShowTime.Minutes))

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Minutes to Hour & minutes

    I have no idea what you just asked for.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  6. #6
    Fanatic Member newprogram's Avatar
    Join Date
    Apr 2006
    Location
    in your basement
    Posts
    769

    Re: Minutes to Hour & minutes

    Does that not work?
    Last edited by newprogram; Aug 23rd, 2007 at 12:59 AM.
    Live life to the fullest!!

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2004
    Location
    Kolkata, India
    Posts
    290

    Re: Minutes to Hour & minutes

    it work but it show in message box,
    but i want it will show in textbox like 3:29


    thanks

  8. #8
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Minutes to Hour & minutes

    You really should apply some thought to the problem before asking for help. You display a string in a MessageBox like this:
    vb.net Code:
    1. MessageBox.Show(myString)
    You display a string in a TextBox like this:
    vb.net Code:
    1. myTextBox.Text = myString
    I've shown you how to create the string you want and I used the MessageBox to show it as an example. If you want to show the string in a TextBox instead then by all means do so. You already know how to create the string so you can do whatever you want with it.
    Last edited by jmcilhinney; Aug 24th, 2007 at 01:04 AM.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  9. #9

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2004
    Location
    Kolkata, India
    Posts
    290

    Re: Minutes to Hour & minutes

    thanks...

    I achive the result using code:
    vb Code:
    1. TextBox2.Text = ShowTime.Hours.ToString + ":" + ShowTime.Minutes.ToString

  10. #10
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [RESOLVED] Minutes to Hour & minutes

    Why not use the String.Format method like I showed you:
    vb.net Code:
    1. TextBox2.Text = String.Format("{0}:{1:00}", ShowTime.Hours, ShowTime.Minutes))
    Note that I've also specified that the minutes be displayed with two digits with "{1:00}". Using your code if the minutes are not double figures you'd end up with a string like "3:9" instead of "3:09". That said, you could still use code like yours to get double-digit minutes if you use ShowTime.Minutes.ToString("00").
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

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