converting Hour number to Time format

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

Guest

Here is what I want to do
Convert 3.5 hours into a time format like 3:30...

Thanks in advance
 
?CDate(3.5 / 24)
03:30:00

?Format(3.5 / 24, "hh:nn")
03:30

CDate() returns DateTime value, Format returns String value.
 
Assuming a table named Table1 with a field called MyHour, a query that would
display the decimal hour as hours:minutes would look like this:

SELECT Format([myhour]/24,"Short Time") AS FormattedHour, CDate([myhour]/24)
AS ConvertedHour
FROM Table1;

and would display the times like so:

FormattedHour ConvertedHour
03:30 3:30:00 AM

However, this will only work for value less than 24 hours. For higher
values, I have a small sample database on my website (see sig below) called
"ConvertStringStuff.mdb" which can handle higher values.
 
The proper way is to use DateAdd:

?DateAdd("n", 3.5*60, #14:50#)
18:20:00

?Format(DateAdd("n", 3.5*60, #14:50#), "hh:nn")
18:20


--
HTH
Van T. Dinh
MVP (Access)



brimil said:
I was able to convert the hours to read in a time format...Is it possible
to now add the 03:30 to a antoher time so it will give the sum of those? It
seems to errror out for me....
For instance: 03:30 (converted from 3.5 hours) + 14:50 (start time) =
18:20
 
Back
Top