Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Conversion to Time format

Status
Not open for further replies.
Feb 16, 2001
44
CA
Hi, guys!

Could you help me?
I need to format minutes to hh:mm:ss
Say, I have 2225.567 min I need to get it in hh:mm:ss


Thanks
 
I would convert the minutes to a date/time variable, then use the Format function to get the hh:mm:ss format.

To convert it to a date/time variable, which is a floating point number measuring time in days, you have to divide by the number of minutes in a day, that is, divide by (60*24) or 1440. Say you want a string formatted as hh:mm:ss. The following expression will give it:
Format(mins / 1440.0, "hh:mm:ss")
Rick Sprague
 
Not quite. The format function as shown above returns only the Hrs, Mins and Sec for the FRACTIONAL day. any Minutes > 1440 will be truncated.

Code:
Public Function basMinsToHrMnSec(Mins As Double) As String

    Dim Days As Integer         'Number of Whole Days
    Dim FractDays As Single     'Fractional Days
    Dim tmpOut As Date          'Temp Storage for Partial Soloution
    Dim tmpDayHrs As Integer    'Temp for Hours
    Dim tmpMins As Integer      'Minutes of Fractional Day
    Dim tmpSecs As Integer      'Seconds of Fractional Day

    Days = Mins \ 1440                      '1440 Minutes = 24 Hrs * 60 Mins
    FractDays = (Mins / 1440) - Days        'Fractional Part of Whole Day
    tmpOut = Format(FractDays, "hh:mm:ss")  'Format the fractional part as Hr:Min:Sec

    tmpDayHrs = (Days * 24) + Format(tmpOut, "hh")      'Actual Hours
    tmpMins = Format(tmpOut, "n")                       'Actual Minutes
    tmpSecs = Format(tmpOut, "s")                       'Actual Seconds
    
    basMinsToHrMnSec = tmpDayHrs & ":" & tmpMins & ":" & tmpSecs    'Format Return Value

End Function

Will return the 'whole enchallidia'



MichaelRed
mred@duvallgroup.com
There is never time to do it right but there is always time to do it over
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top