Subject Re: [IBO] Time Clock
Author Gordon Hamm
What SQL would you use to get secondsbetween for 2 times? Thanks for the aid.

----- Original Message -----
From: Helen Borrie
To: IBObjects@yahoogroups.com
Sent: Wednesday, May 27, 2009 8:14 PM
Subject: Re: [IBO] Time Clock





At 11:19 AM 28/05/2009, you wrote:
>Ive got 2 fields, both of type Time
>
>Now, I get these value.. respectivly
>
>Time1:=TempQuery2.FieldbyName('Visit1_Time_In').AsDateTime; (val is
>Time is 7:00 am)
>Time2:=TempQuery2.FieldbyName('Visit1_Time_Out').AsDateTime; (val is
>Time is 7:05 am)
>
>Now, I was using a function
>
>HowmanyMinutes:=MinutesBetween(Time2,Time1);
>
>It returned a value of 4 minutes. Weird.
>
>So Then I did
>
>HowManySeconds := SecondsBetween(Time2,Time1);
>
>And found that it returned 299 seconds (Should be 300)
>
>Any ideas why? The value appears right in the database, but its a second off
>when doing the math.

Casting rules for float to integer.

Delphi's DateTime values are floats which, as you know, never exist as exact numbers. When Delphi casts them to integer, you literally get the integer part of the float. Rewrite your functions so that you end up with a float that you can apply your own rounding rules to.

Better still, do the intervals calculation in your SQL. For the interval between two time-part values, it returns an exact number of seconds as DECIMAL(9,4). Bring the results into your application AsCurrency.

Helen






[Non-text portions of this message have been removed]