Converting a Time Value to a Decimal

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

Guest

Hell

I am trying to convert a time value in the format HH:NN:SS to a decimal valu
i.e. 22:30:00 to 20.5 hours

Hel

I have tried typecasting the value into a long, double, int, and others but to no avail. I have also tried to extract the hours part of the value and use that for calculation but it is proving inaccurat

Is there anyone who can help in these desperate times!

Thanks in advanc

Darre

P.s. please post a reply before next friday thanks!!!
 
Darren,

Date/Time fields in Access are just muneric fields of type Double, where the
integer part is the date (starting 01/01/1900) and the decimal part ids the
time. So, if you take your time filed (or variable) and multiply by 24
(hours in a day) you will get what you want.

HTH,
Nikos

Darren said:
Hello

I am trying to convert a time value in the format HH:NN:SS to a decimal value
i.e. 22:30:00 to 20.5 hours.

Help

I have tried typecasting the value into a long, double, int, and others
but to no avail. I have also tried to extract the hours part of the value
and use that for calculation but it is proving inaccurate
 
Hi Niko

Upon multiplying the field by 24 the query returned a #Error, i believe this is due to the field being of an invalid type to perform a numeric calculation

I thought the answer was something to do with the CDec( ) function, but i'm unsure of the correct syntax as it needs to be performed in a modul

Darren
 
Hi,


It is probably because the "date" is, at that point, a string, not a
date_time value.

24 * CDate( expression )

should convert the expression, in whatever it is, into a date, which is a
numerical value that can then be multiplied by 24 (to get hours rather than
"days").





Hoping it may help,
Vanderghast, Access MVP


Darren said:
Hi Nikos

Upon multiplying the field by 24 the query returned a #Error, i believe
this is due to the field being of an invalid type to perform a numeric
calculation.
I thought the answer was something to do with the CDec( ) function, but
i'm unsure of the correct syntax as it needs to be performed in a module
 

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