Subject Re: time data type and elapsed
Author steve_carter_ben
Lucas,
> If you are sure that the difference between these fields is less
tahn
> one day (otherwise you have to use the crystal bowl function) how
about
> adding the value for one day if your result is less than zero?

Thanks. Of course -- why didn't I think of that?
So, for example, I can get the elapsed hours with something like
this sample SQL:
select
timeofpickup, timeofdropoff,
( (timeofdropoff - timeofpickup) + 86400) / 3600
from reserve
where timeofdropoff < timeofpickup

It's funny how simple the answer is once you know the answer!

As for the "crystal bowl" function (<grin>) -- this is a limousine
reservation app. I guess if the customer was going to keep the car
more than 24 hours, they'd pay a flat rate. So far, we haven't had
customers that extravagant.

Steve
Steve

--- In firebird-support@yahoogroups.com, Lucas Franzen <luc@r...>
wrote:
>
>
> steve_carter_ben schrieb:
>
> > Helen,
> > Thanks for your responce, but I can see I did not make myself
clear.
> > It is not the fields of type date that are giving me trouble,
but
> > the fields of type time.
> > For example, I have a field 'timeofpickup' with value '530 PM'
and a
> > field 'timeofdropoff' with a value of 1:30 AM.
> > (I realize that internally these are stored as integers
representing
> > milliseconds since midnight).
> >
> > I can, of course do the following:
> > select
> > timeofpickup, timeofdropoff,
> > (timeofdropoff - timeofpickup)...
> >
> > but that gives me the unuseful value of -57600
> > <grin>.
>
> Which is perfectly ok since a time field doesn't store the day -
it's a
> time field not a datetime field.
> If you are sure that the difference between these fields is less
tahn
> one day (otherwise you have to use the crystal bowl function) how
about
> adding the value for one day if your result is less than zero?
>
> One day = 24 hours * 60 minutes * 60 seconds = 86400 seconds.
>
> if you add 86400 to -57600 you'll get 28860 seconds which is
exactly 8
> hours...
>
> You can use (for example) stored proc to check for results below
zero.
>
> Luc.