in reply to Re: Check Time between 2 other times
in thread Check Time between 2 other times

select 1 where $my_date_time > $start_date_time and $my_date_time < $end_date_time

That’s un-SQLish. It can be better written as

SELECT 1 WHERE $my_date_time BETWEEN $start_date_time AND $end_date_time

(And of course, you’d pass the values in using placeholders, not by interpolating them into the SQL.)

Makeshifts last the longest.

Replies are listed 'Best First'.
Re^3: Check Time between 2 other times
by terce (Friar) on Nov 03, 2005 at 14:30 UTC
    Absolutely, on both points. I was trying to make the logic as clear as possible for the OP.

    (also, I'm not sure whether all SQL dialects support BETWEEN)

      It’s part of SQL92, at least. MySQL, PostgreSQL, SQLite and Oracle support it. I’d be surprised if any common RDBMS does not.

      Makeshifts last the longest.