Subject Re: calculating sum of times
Author Ali Gökçen
Hi d_dude_2003,

Totaltime should be integer or bigint depends on your table fat.

Time2-Time1 gives time difference in seconds.
any way if you want to use Totaltime as Time format then use:

TotalTime = cast('00:00' as TIME) + (Time2-Time1)


if you want to get sum of totaltime then:

sum(totaltime) -- totaltime as number and result as number of seconds

sum(totaltime - cast('00:00' as TIME)) -- totaltime as TIME and
result as number of seconds

seconds = sum(totaltime)

number_of_days = seconds / 86400 -- 3600*24

seconds = seconds - (number_of_days * 86400)

number_of_hours = seconds / 3600

seconds = seconds - (number_of_hours*3600)

number_of_minutes = seconds / 60

total_time_as_text = number_of_days || 'Day,'
|| number_of_hours || 'Hour'
|| number_of_minutes || 'Minutes'

etc..

Regards,

-Ali


--- In firebird-support@yahoogroups.com, "d_dude_2003"
<d_dude_2003@y...> wrote:
> Hi folks,
>
> I have the following table
>
> ID Time1 Time2 TotalTime
>
> Time1 and Time2 are posted by stored procedure. Then
> in the end of processing i am doing
>
> UPDATE MyTable SET TotalTime = Time2 - Time1
>
> Am i right to assume that TotalTime will now hold the amount
> of time passed since Time1 till Time2?
>
> Now...I need to calculate SUM(TotalTime) for all records in a
table..
> And get the hours...How do i go about that?
>
> Thanx alot.