Search if a single date falls in range of two dates stored in the database

2 views
Skip to first unread message

ACTRAiSER

unread,
Nov 6, 2009, 2:21:53 AM11/6/09
to Thinking Sphinx
Hi everyone,

I have stored two dates with a tournament model in the database
"registration_accepted_from_date" and
"registration_accepted_to_date".

In the search form with a single checkbox i want to find all
tournaments where registration is currently open, meaning, where
Time.now lies within the range of those two stored dates.

#my indexing should be straight forward:
define_index do
has registration_accepted_from_date
has registration_accepted_to_date
end

Now what? :-) I know how to search a single date field in the database
with a range composed of two dates, e.g. from a form. But how does
the opposite work: you have the two dates already stored in the
database and want to check if a single date (e.g. Time.now) lies
within the range of those stored dates?

Hints are appreciated :-)

greets
-act



ACTRAiSER

unread,
Nov 6, 2009, 2:49:24 AM11/6/09
to Thinking Sphinx
Oh my .. it was too early i guess .. here is the simple solution:

define_indexes do
has "registration_accepted_from_date >= CURDATE() AND
registration_accepted_to_date <= CURDATE()", :as
=> :registration_accepted, :type => :boolean
end

Nevermind.

Greets
-act

ACTRAiSER

unread,
Nov 6, 2009, 2:58:10 AM11/6/09
to Thinking Sphinx
For the Sake of completeness. The better solution after checking mysql
manual would be

define_indexes do
has "NOW() BETWEEN registration_accepted_from_date AND
registration_accepted_to_date", :as => :registration_accepted, :type
=> :boolean
end

greets
-act
Reply all
Reply to author
Forward
0 new messages