views:

26

answers:

1

I've been banging my head at this one:

I have a table with columns start_time an end_time as well as start_date and end_date, and I have a Time object called test_time. I need to be able to match these values in a sql query. ie.

Reservation.find :all, :conditions => ["'start_time' <= ? AND 'end_time' >= ?", test_time, test_time]

Assuming we are only looking at Time and not Date, how can I determine whether or not test_time is within the range of time beginning at start_time and ending at end_time. In other words, 11:30am is between 11:15am and 11:45am. I've tried SQL BETWEEN clause, but was unsuccessful.

A: 

you may be intereted in installing the ar-extensions plugin. It provides an easy syntax to handle these types of queries. I use it to find if a given latitude/longitude position is within a certain radius:

ar-extensions

ennuikiller
I took a look at it, but I would prefer to not have to alter the core of Rails (I think that is what your suggestion does), and the documentation for that extension leaves a lot to be desired. Is there a plugin-free way to accomplish the above?
Tom