Format Time to display with Decimals

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am using Access 2003. I am trying to return time in a report using hours
and minutes. I want the time to display in decimals (ie: 1.5 hours). Can't
seem to find the right format.
 
Well, in the debug window:

? time
11:17:18 PM

? format(hour(time) + (minute(time) / 60),"00.00")
23.28

If I had a *bunch* of places and several reports, then build a global
function in a standard module, and then use that for forms, and reports.

ig:

Public Function nHours(t As Variant) As Variant

If IsNull(t) Then Exit Function

nHours = Format(Hour(t) + (Minute(t) / 60), "00.00")

End Function

Then, in a query you can use

nhours([Timefield]).

And, in a report, simply create a text box (make sure it don't have the
same name as a existing field). for the control source of the text box, just
go

=nHours([TimeFieldName])
 
I can't get this to work for me. My request was not really clear. My data
is in "Short Time" format (14:35 hrs). I have taken those numbers and
created entries using math [Total Time = 2:30 (hr:mins)]. The numbers I am
working with are in Hours:Minutes, and I want to display them in Hours.Hours
(decimals)(2.5 hrs). Does this help?
 
Well, if I try my function

in the debug window

? nhours(#14:35#)
14.58

? nhours(#14:30#)
14.50

So, the above does seem to work.
I have taken those numbers and
created entries using math [Total Time = 2:30 (hr:mins)]. The numbers I
am
working with are in Hours:Minutes, and I want to display them in
Hours.Hours
(decimals)(2.5 hrs). Does this help?

if we go

? nhours(#2:30#)
02.50

The above does return 2.5 hours for 2:30 minutes.

Perahps you don't want the leading/traing zeros?

Is the issue now you want 12 hour format???
 
I really appreciate your help with this. Your suggestions will help, except
they are just over my head as far as abilities go. I have worked with
Formatting codes before, but nothing as involved as this one:
format(hour(time) + (minute(time) / 60),"00.00"). I have looked through the
help files, and can't find anything similar to it. The field that I need
formatted is named "Total_Time". Could you show me where it fits in your
line of code?

Again, Thanks for all or your help
Balfour211

Albert D. Kallal said:
Well, if I try my function

in the debug window

? nhours(#14:35#)
14.58

? nhours(#14:30#)
14.50

So, the above does seem to work.
I have taken those numbers and
created entries using math [Total Time = 2:30 (hr:mins)]. The numbers I
am
working with are in Hours:Minutes, and I want to display them in
Hours.Hours
(decimals)(2.5 hrs). Does this help?

if we go

? nhours(#2:30#)
02.50

The above does return 2.5 hours for 2:30 minutes.

Perahps you don't want the leading/traing zeros?

Is the issue now you want 12 hour format???
 
Balfour211 said:
I really appreciate your help with this. Your suggestions will help,
except
they are just over my head as far as abilities go. I have worked with
Formatting codes before, but nothing as involved as this one:
format(hour(time) + (minute(time) / 60),"00.00"). I have looked through
the
help files, and can't find anything similar to it. The field that I need
formatted is named "Total_Time". Could you show me where it fits in your
line of code?

You just use my function in a expression in a report...

So, for example, in a report, you create a new text box, you then use for
the expression

=(nHours([Total_Time]))

You can also use the above in a query, or even on a form (however, function
expressions on a form are NOT updatable, so, this tip might not be of use on
a form if the displayed expression needs to be editable).

So, the sample code I posted would be placed in a standard code module (give
the module a name of module1 - that is the default when you create a module.
Paste in my sample code, and then make use you hit save....


At this point, anywhere, or anytime you need a formatted time value, you use
the nHours() function.

You could also in your reports, or wherever use the full expression, but
that is bit clumsy when you have to do this over and over. so, you could on
a report create a text box, and use the following expression (remember,
don't give the text box the same name as an existing field when you do
this).

= ( Format(Hour([Total_Time]) + (Minute([Total_Tiime]) / 60), "00.00") )

I made a function since the above expression is rather painful to have to
type into a report each time you need a formatted time value.
 
That worked perfectly. That was exactly what I needed. Thanks for taking
the time to give that little extra help (I'm still learning).

Balfour211

Albert D. Kallal said:
Balfour211 said:
I really appreciate your help with this. Your suggestions will help,
except
they are just over my head as far as abilities go. I have worked with
Formatting codes before, but nothing as involved as this one:
format(hour(time) + (minute(time) / 60),"00.00"). I have looked through
the
help files, and can't find anything similar to it. The field that I need
formatted is named "Total_Time". Could you show me where it fits in your
line of code?

You just use my function in a expression in a report...

So, for example, in a report, you create a new text box, you then use for
the expression

=(nHours([Total_Time]))

You can also use the above in a query, or even on a form (however, function
expressions on a form are NOT updatable, so, this tip might not be of use on
a form if the displayed expression needs to be editable).

So, the sample code I posted would be placed in a standard code module (give
the module a name of module1 - that is the default when you create a module.
Paste in my sample code, and then make use you hit save....


At this point, anywhere, or anytime you need a formatted time value, you use
the nHours() function.

You could also in your reports, or wherever use the full expression, but
that is bit clumsy when you have to do this over and over. so, you could on
a report create a text box, and use the following expression (remember,
don't give the text box the same name as an existing field when you do
this).

= ( Format(Hour([Total_Time]) + (Minute([Total_Tiime]) / 60), "00.00") )

I made a function since the above expression is rather painful to have to
type into a report each time you need a formatted time value.
 

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

Back
Top