Subject | RE: [firebird-support] Time between two times |
---|---|
Author | Leyne, Sean |
Post date | 2008-06-19T19:22:32Z |
Lee,
SELECT
...
WHERE
StartTime_Field => :TargetTime
AND (
EndTime_Field <= :TargetTime
OR EndTime_Field < StartTime_Field
)
recommend storing a true Date/Time values for the Start and End times.
It would make the logic much easier and faster -- since you could build
a compound index on StartTime and EndTime fields.
Sean
> I'm wondering what would be the best way to pull a record from thepassed
> database based on a StartTime and EndTime (both time fields) and a
> value of Time.effected by
> I know the BETWEEN command, but I'm wondering how it will be
> the way time is circular.BETWEEN is not the right answer.
> For instance, if the StartTime is 3:00 PM and the EndTime is 1:00 AMand
> the current time is 5:00 PM, I don't think it will return the correctbut
> values since it'll see the EndTime, 1:00 AM as part of the same day,
> earlier.The SQL is:
SELECT
...
WHERE
StartTime_Field => :TargetTime
AND (
EndTime_Field <= :TargetTime
OR EndTime_Field < StartTime_Field
)
> I'm assuming the best way to handle will be within the applicationitself.
> My first impulse is to build a flag into the app that the user canspecify
> that the end time value extends to the following day.The above SQL eliminates the need for the flag, although I would
recommend storing a true Date/Time values for the Start and End times.
It would make the logic much easier and faster -- since you could build
a compound index on StartTime and EndTime fields.
Sean