Hours formatting issue

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

Guest

I have a time field with hh:mm:ss formatting & I want to convert the hours in
my query into decimal format. i.e 1:30:00 = 1.5, 2:45:00 = 2.75 etc. Any
help would be greatly appreciated.
 
Tony,

Assuming your time is actually in DateTime format:
Hour(myTime) + (Minute(myTime)/60) + (Second(myTime)/360)

For example, if the current time is TimeSerial(10,30,30), the above formula
will return:
10.5833333333333

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia
 
Oops,

Just realised I'd left a zero off:

Hour(myTime) + (Minute(myTime)/60) + (Second(myTime)/3600)
10.5083333333333

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia
 
Hi,


24*CDbl( your_time_value )

as in


? 24 * CDbl(#1:30:00#)
1.5



Hoping it may help,
Vanderghast, Access MVP
 
This also works

? 24 * #1:30:00#
1.5

I guess the # delimiters are an explicit convert to datetime (double).
 
Hi,


The # is a delimiter, mainly to differentiate the date #1-2-3# from 1
minus 2 minus 3. VBA allows many implicit conversion, here, from a date to
a float, without having to explicitly tell it, but CDbl just explicitly ask
for the conversion (rather than relaying on implicit conversion). CDbl, in
my mind, makes it more evident that we really want to get a floating point
value, from the date and time, and then, that we will multiply it by 24. It
is a kind of automatic-comment built in the code. It is not necessary, in
VBA, to use the explicit conversion, indeed.


Hoping it may help,
Vanderghast, Access MVP
 
Tony,

Just so you know, Michael Walsh's suggestion is the better way to go. It's
just as good, but is a more professional coding approach.

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia
---------------------------

TonyL said:
Thanks. Thank worked a treat. Thanks to the others that responded too.

Tony
 
Back
Top