Time conversion and calculation

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

Guest

I have a time field with values from 2 to 3 digits long, representing duration values; for example

30 (which equals 30 minutes
100 (which equals 1 hour
130 (which equals 1 hour 30 minutes
etc

I need to calculate the number of quarter-hours (15-minute intervals) within each of these values, and am at a loss on how to do this. I've contemplated dividing the field into two separate fields, but run into a problem extracting the hour digit since not every value has three digits (not to mention the result would be a text field that would prevent calculations). I am not familiar with VBA and how to create macros, so I'm pretty much limited to functions. Any help would be greatly appreciated

Thanks
Eric
 
You can use the Format function to convert both your 2 and 3 digit
durations to 3 digit strings:

strValue = Format(intValue, "000")

Now, you can extract the first digit as hours, and the 2nd and 3rd digits as
minutes:

intHours = CInt(Left(strValue, 1))
intMinutes = CInt(Right(strValue, 2))

That last one could also be

intMinutes = CInt(Mid(strValue, 2))

Hopefully that's enough to get you going.

--
Doug Steele, Microsoft Access MVP

(No private e-mails, please)


Eric Stephens said:
I have a time field with values from 2 to 3 digits long, representing duration values; for example:

30 (which equals 30 minutes)
100 (which equals 1 hour)
130 (which equals 1 hour 30 minutes)
etc.

I need to calculate the number of quarter-hours (15-minute intervals)
within each of these values, and am at a loss on how to do this. I've
contemplated dividing the field into two separate fields, but run into a
problem extracting the hour digit since not every value has three digits
(not to mention the result would be a text field that would prevent
calculations). I am not familiar with VBA and how to create macros, so I'm
pretty much limited to functions. Any help would be greatly appreciated!
 

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

Similar Threads


Back
Top