Results 1 to 15 of 15

Thread: [RESOLVED] trying to convert minutes to hours disnt calculate right why?

  1. #1

    Thread Starter
    Enjoy the moment
    Join Date
    Feb 2011
    Location
    Barrio Del pilar madrid spain
    Posts
    5,204

    Resolved [RESOLVED] trying to convert minutes to hours disnt calculate right why?

    hey,
    i have some minutes that i want to calculate to hours
    but it shows me the wrong calculation why?

    salsa 45 minutes
    danny 45 minutes
    total in hours 1.30 Hours
    but in my code it shows me 1.50
    Code:
    FormatNumber(TotalHours / 60, 2, vbTrue)
    tnx for any help
    salsa

  2. #2
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    9,143

    Re: trying to convert minutes to hours disnt calculate right why?

    45 minutes plus 45 minutes IS 1.5 hours, that is, 1 hour and 30 minutes. It is calculating correctly.

  3. #3
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    9,143

    Re: trying to convert minutes to hours disnt calculate right why?

    Example:

    text1 has 45 minutes, text2 has 45 minutes

    Code:
    Private Sub Command1_Click()    Dim TotalHours As Double
        TotalHours = CDbl(Text1.Text) + CDbl(Text2.Text)
        Text3.Text = FormatNumber(TotalHours / 60, 2, vbTrue)
    End Sub

  4. #4

    Thread Starter
    Enjoy the moment
    Join Date
    Feb 2011
    Location
    Barrio Del pilar madrid spain
    Posts
    5,204

    Re: trying to convert minutes to hours disnt calculate right why?

    Quote Originally Posted by SamOscarBrown View Post
    45 minutes plus 45 minutes IS 1.5 hours, that is, 1 hour and 30 minutes. It is calculating correctly.
    45 minutes and 45 minutes is 1.30 not 1.50
    its a hour and a half

  5. #5
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    9,143

    Re: trying to convert minutes to hours disnt calculate right why?

    1.3 hours is 78 minutes. 1.5 hours is 90 minutes. 45 plus 45 equals 90...hence, 1.5 hours (90) minutes is correct.

    If you had 45 minutes plus 33 minutes (total-78 minutes), the result would be 1.3.

    45 minutes and 45 minutes is NOT 1.30...it is 1.50!

    You're thinking is not quite right.

    Sammi

  6. #6
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    9,143

    Re: trying to convert minutes to hours disnt calculate right why?

    If you're thinking 1.3 means 1 hour and 30 minutes, you're incorrect.

  7. #7

    Thread Starter
    Enjoy the moment
    Join Date
    Feb 2011
    Location
    Barrio Del pilar madrid spain
    Posts
    5,204

    Re: trying to convert minutes to hours disnt calculate right why?

    so i do i calculate 30 + 15+ 60? 1.75?

  8. #8
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: trying to convert minutes to hours disnt calculate right why?

    Quote Originally Posted by salsa31 View Post
    so i do i calculate 30 + 15+ 60? 1.75?
    Yes. 1 hour and 45 minutes is same as 1.75 hours. Add up your total minutes and then divide by 60

    In your original post, when you were saying that you expected 1.30 instead of 1.5, the 1.3 could better be expressed as hours & minutes

    Example: 45 mins + 45 mins = 1 hr 30 mins: Format(Dateadd("n", 45+45,0),"h.n") = 1.3
    Example: 45 mins + 45 mins = 1.5 hours: (45+45)/60 = 1.5
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  9. #9

    Thread Starter
    Enjoy the moment
    Join Date
    Feb 2011
    Location
    Barrio Del pilar madrid spain
    Posts
    5,204

    Re: trying to convert minutes to hours disnt calculate right why?

    it doesn't make any sense Lavolpe sir

  10. #10

    Thread Starter
    Enjoy the moment
    Join Date
    Feb 2011
    Location
    Barrio Del pilar madrid spain
    Posts
    5,204

    Re: trying to convert minutes to hours disnt calculate right why?

    got it now sir Lavolpe thank you
    tnx Sami

  11. #11
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: trying to convert minutes to hours disnt calculate right why?

    Quote Originally Posted by salsa31 View Post
    it doesn't make any sense Lavolpe sir
    Sorry, your question doesn't make a lot of sense to us which is why we are a bit confused.

    Either you want to display your totals as: a) fractions of hours or b) hours and minutes. 90 minutes = 1 hr 30 mins or 1.5 hours. Anyone seeing a value of "1.3 hours" does not naturally interpret that value as 1 hour and 30 minutes, they would interpret it as 1 hour plus 1/3 of an hour (1 hour and 20 minutes).

    Edited: We posted at same time. Ignore this reply if you have your answer.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  12. #12

    Thread Starter
    Enjoy the moment
    Join Date
    Feb 2011
    Location
    Barrio Del pilar madrid spain
    Posts
    5,204

    Re: [RESOLVED] trying to convert minutes to hours disnt calculate right why?

    got it now sir Lavolpe thank you

  13. #13
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    9,853

    Re: trying to convert minutes to hours disnt calculate right why?

    Quote Originally Posted by LaVolpe View Post
    Anyone seeing a value of "1.3 hours" does not naturally interpret that value as 1 hour and 30 minutes, they would interpret it as 1 hour plus 1/3 of an hour (1 hour and 20 minutes).
    Sorry, I can't resist. Personally, I'd interpret 1.3 hours as 1 hour and 3/10ths of an hour. Or, 1 hour and 18 minutes. Or 1:18.

    Y'all Take Care,
    Elroy
    Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.

  14. #14
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: [RESOLVED] trying to convert minutes to hours disnt calculate right why?

    Of course, I was using simple rounding in my old head: a third-ish (0.3) of an hour is easier to mentally calculate than 60*.3 -- don't work harder than I need to.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  15. #15
    PowerPoster ChrisE's Avatar
    Join Date
    Jun 2017
    Location
    Frankfurt
    Posts
    3,042

    Re: [RESOLVED] trying to convert minutes to hours disnt calculate right why?

    Hi salsa,

    I prefer working with minutes, but in some will want Decimal.

    here a sample for both ways....
    Code:
    Private IsModeDecimal As Boolean
    
    
    Public Function isDecimal() As Boolean
          isDecimal = IsModeDecimal
    End Function
    
    
    
    Private Sub Command1_Click()
    Text2.Text = MinutenToZeit(Text1.Text, False)
    
    
    IsModeDecimal = Text1.Text '
    Text3.Text = MinutenToZeit(Text1.Text, IsModeDecimal, 1)
    End Sub
    
    Private Sub Form_Load()
    Text1.Text = 78
    End Sub
    
    
    Public Function MinutenToZeit(Minuten As Long, IsModeDecimal As Boolean, _
                                  Optional LenghtStunden As Long = 2) As String
    'rechnet Minuten um in ZeitString
    
       Dim S() As String
       Dim Std As String
       
          Std = String$(LenghtStunden, "0")
          ReDim S(1)
          If Not isDecimal Then
             S(0) = Format(Minuten \ 60, Std)
             S(1) = Format(Minuten Mod 60, "00")
             MinutenToZeit = Join(S(), ":")
          Else
             S(0) = Format(Minuten \ 60, Std)
             S(1) = Format(((Minuten Mod 60) * 100) / 60, "00")
             MinutenToZeit = Join(S(), ",")
          End If
    End Function
    regards
    Chris
    Last edited by ChrisE; Jul 22nd, 2018 at 12:24 PM.
    to hunt a species to extinction is not logical !
    since 2010 the number of Tigers are rising again in 2016 - 3900 were counted. with Baby Callas it's 3901, my wife and I had 2-3 months the privilege of raising a Baby Tiger.

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