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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Converting Seconds to Minutes a nice way?

Status
Not open for further replies.

CTOROCK

Programmer
May 14, 2002
289
US
How would I convert seconds to minutes so I can display it like this XX:XX.

For example: I have 450 seconds. It turns out to be 7:30 minutes. It reports as 7.5
What I am doing is during run time or a report, geting the left character of the string, then geting the right 2 characters, multiply .5 * 60 and get that and putting the two together with a ":" in between them to display 7:30. Is there a better way? "The greatest risk, is not taking one."
 
If you have used vb code I would suggest the following:

Dim two variables to hold the calculation results

Dim intMin
Dim intSec

The calculations use the backslash and mod operators to return the appropriate values:

intMin = TimeControl \ 60 (will return integer value)
intSec = TimeControl mod 60 (will return the remainder)

DisplayControl = intMin & ":" & intSec

Put this in the On Format event for the detail section. Larry De Laruelle
ldelaruelle@familychildrenscenter.org

 
Hmmmmmmmmmmmmmm,

IF you have the start & stop times in generic Dte/Time Variables, the following could be used as an EXAMPLE for a fairly direct calculation. It (the following 'procedure') id NOT intended for use in a production app, as it includes NO error checking/recovery, and is STRICTLY limited in the functionallity, to the minutes and seconds display.

Code:
Public Function basSec2MinSec(TmStrt As Date, TmEnd As Date) As String

    'Michael Red    6/12/02
    'Convert Start / Stop Times to formatted Time String
    'Sample Usage:  ? basSec2MinSec(Now, DateAdd("s", 450, Now))
    '7:30

    Const SecsPerDay = 86400

    MySecs = DateDiff("S", TmStrt, TmEnd)

    basSec2MinSec = Format((MySecs / SecsPerDay), "n:ss")

End Function
MichaelRed
m.red@att.net

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