display decimal as hours:minutes

R

RJB

I have a really simple form that is to figure how long something is going to
take. I know all the information needed, the problem is getting it to
display properly. Here's the example.

50 copies of 200 pieces. (=10,000)
The machine runs at 90 pieces per hour. (=111.1111111)
How many hours will it take to finish? (= 1.85)

I need to display 1.85 as 1 hour and 51 minutes (1.85 in hours:minutes)

Simply changing the display format to "Short Time" does not work...it comes
up with 20:26

How can I do this?
 
J

Jeff Boyce

You didn't mention what the data type is. Is the 1.85 a calculated value,
or have you stored it (not a good idea)?

You'll need to "parse" the number into the way you want it displayed.
You'll be using the integer portion (in your example, "1") to get the number
of hours, and multiplying the decimal portion (".85") times 60 to get the
minutes (probably only the integer portion of that answer), and
concatenating them together with the appropriate separator.

Regards

Jeff Boyce
Microsoft Office/Access MVP
 
J

Jeff Boyce

You didn't mention what the data type is. Is the 1.85 a calculated value,
or have you stored it (not a good idea)?

You'll need to "parse" the number into the way you want it displayed.
You'll be using the integer portion (in your example, "1") to get the number
of hours, and multiplying the decimal portion (".85") times 60 to get the
minutes (probably only the integer portion of that answer), and
concatenating them together with the appropriate separator.

Regards

Jeff Boyce
Microsoft Office/Access MVP
 
F

fredg

I have a really simple form that is to figure how long something is going to
take. I know all the information needed, the problem is getting it to
display properly. Here's the example.

50 copies of 200 pieces. (=10,000)
The machine runs at 90 pieces per hour. (=111.1111111)
How many hours will it take to finish? (= 1.85)

I need to display 1.85 as 1 hour and 51 minutes (1.85 in hours:minutes)

Simply changing the display format to "Short Time" does not work...it comes
up with 20:26

How can I do this?

You can't use a Time format because the value is not a point in time,
it is an amount.
You can, however, display it as n:nn

= int([FieldName]) & Format((([FieldName] - int([FieldName]))) *
60,"#:00")

? int(1.85) & Format(((1.85 - int(1.85))) * 60,"#:00")
1:51
 
R

RJB

Thanks guys. The number is calculated (not stored) and the code provided
did solve the problem.

Thank ya much.
RJB


fredg said:
I have a really simple form that is to figure how long something is going
to
take. I know all the information needed, the problem is getting it to
display properly. Here's the example.

50 copies of 200 pieces. (=10,000)
The machine runs at 90 pieces per hour. (=111.1111111)
How many hours will it take to finish? (= 1.85)

I need to display 1.85 as 1 hour and 51 minutes (1.85 in hours:minutes)

Simply changing the display format to "Short Time" does not work...it
comes
up with 20:26

How can I do this?

You can't use a Time format because the value is not a point in time,
it is an amount.
You can, however, display it as n:nn

= int([FieldName]) & Format((([FieldName] - int([FieldName]))) *
60,"#:00")

? int(1.85) & Format(((1.85 - int(1.85))) * 60,"#:00")
1:51
 
G

Guest

FYI, here is a function I put together for a similar question. Maybe it will
do some good:

Public Function HrMinSecTime(ByVal dtmStartTime, ByVal dtmEndTime) As String
Dim dblTimeDiff As Double

On Error GoTo HrMinSecTime_Error

dblTimeDiff = DateDiff("s", dtmStartTime, dtmEndTime)

HrMinSecTime = Format(dblTimeDiff \ 3600, "00:") & _
Format((dblTimeDiff Mod 3600) \ 60, "00:") & _
Format((dblTimeDiff Mod 3600) Mod 60, "00")

HrMinSecTime_Exit:

On Error Resume Next
Exit Function

HrMinSecTime_Error:

MsgBox "Error " & Err.Number & " (" & Err.Description & _
") in procedure HrMinSecTime of Module modDateFunctions"
GoTo HrMinSecTime_Exit
End Function
 
R

RJB

Thanks Dave.
Is there an easy way to make this account for days as well? (shouldn't come
up, but on the off chance they get something that will take more than 24
hours of machine time, it might be a good catch all to include now rather
than later.)
 
G

Guest

It is okay for it to run over a day. If, for example, it were 1 day, 3 hrs,
15 min, 3 sec, it would show 27:15:03
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top