Subject Re: [ib-support] TIME PROBLEM
Author Paul Schmidt

On 25 Mar 2002 at 12:40, apatri2000 wrote:

> Hi all.
> I have a problem:
> Got a field TEMPO_UNITARIO ( UNITARY_TIME ) declared as numeric( 9,4 )
> in which i put the TIME necessary to build an object, e.g. 0,20 stay
> for 20 minutes, 1,45 stay for 1 hour and 45 minutes. Another field
> PEZZI ( PIECES ) declared as NUMERIC( 9,4 ) hold the number of objects
> to build eg 3 stay for 3 objects to build. Problem: how to calculate
> the total amount of time necessary to build all the objects---->
> TOTAL_TIME = UNITARY_TIME * PIECES obvously not work.

Your method for storing times is a little odd, typically you store times as either a
time field (or time portion of a date/time field), or you store it as a number of time
periods, either hours, minutes or seconds (so 1 hour 45 minutes would be stored as
1,75 hours). Storing the time 1 hour 45 minutes as 1,45 (or 1.45 in English) is
unusual because of this problem.

Now an Interbase/Firebird database time field (Dialect 3 ) can be retrieved as the
number of seconds since a given time period, so if you want the number of minutes
declare UNITARY_TIME as a TIME field. Then the math is simple
(UNITARY_TIME / 60) * PIECES to get the number of minutes. You can divide
that by 60 to get the hours, and modulus it by 60 to get the number of minutes, put
the two together to get a displayable time.



Paul Schmidt
Tricat Technologies