Convert decimal hours

S

scott

How can I convert a subform control total that contains a decimal value like
below of 2.51 hours into a "real" time format like 2:30:60 which stands for
HHMMSS? I need a formula for a text box control.

2.51 hours = 2:30:60
 
G

Graham Mandeno

Hi Scott

Assuming you want only to display the formatted time and not edit it, the
answer is straightforward.

You can write a function to convert the number to a string (take off the
integer portion [hours], multiply by 60, take off the integer portion
[minutes], etc). Then set the ControlSource of your textbox to:
=ConvertHoursToHHMMSS( [HoursField] )

However, there is an easier trick which relies on the fact that in a
date/time data type, the hours are represented as a decimal part of a day.

Set your textbox's ControlSource to:
=[HoursField]/24
(i.e. convert hours to days)

Then set its Format property to:
hh:nn:ss
(note that minutes is nn, not mm)
 

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