Adding Time

  • Thread starter Thread starter Kathy Webster
  • Start date Start date
K

Kathy Webster

I am trying to add the total music length in minutes for a soundtrack. My
table has fields for [hrs], [min], and [sec] for each record.

To obtain a sum of total length of time IN MINUTES for all records in a
subset, my formula in the query is:

sum([hrs]*60+[min]+[sec]/60)

I am not getting an accurate sum in minutes. It can be as much as a minute
or two off, depending on how many records are in my subset. Is there a way
to make it more accurate?

Thank you!
Kathy
 
You're probably getting caught with rounding errors, a little bit on each
record. Instead of summing the minutes, sum the seconds then convert back to
minutes. This will let you sum integer values (unless you have fractions of
seconds). In fact, the longer you deal with integers instead of floating
point numbers, the more accurate your result will be. There are some
floating point types that don't have as much problem with this as others,
but integers don't have the problem at all.

Sum([hrs]*3600+[min]*60+[sec])/60
 
Thank you.

Wayne Morgan said:
You're probably getting caught with rounding errors, a little bit on each
record. Instead of summing the minutes, sum the seconds then convert back
to minutes. This will let you sum integer values (unless you have
fractions of seconds). In fact, the longer you deal with integers instead
of floating point numbers, the more accurate your result will be. There
are some floating point types that don't have as much problem with this as
others, but integers don't have the problem at all.

Sum([hrs]*3600+[min]*60+[sec])/60

--
Wayne Morgan
MS Access MVP


Kathy Webster said:
I am trying to add the total music length in minutes for a soundtrack. My
table has fields for [hrs], [min], and [sec] for each record.

To obtain a sum of total length of time IN MINUTES for all records in a
subset, my formula in the query is:

sum([hrs]*60+[min]+[sec]/60)

I am not getting an accurate sum in minutes. It can be as much as a
minute or two off, depending on how many records are in my subset. Is
there a way to make it more accurate?

Thank you!
Kathy
 
Back
Top