From: Morgan Morgan on
i have to count how many records are in a database that have a start
time of 11:00 for an entire year. the problem is, i can't seem to find
out how to coax rails into ignoring the date to just search for a time.
--
Posted via http://www.ruby-forum.com/.

From: Ammar Ali on
Morgan Morgan wrote:
> i have to count how many records are in a database that have a start
> time of 11:00 for an entire year. the problem is, i can't seem to find
> out how to coax rails into ignoring the date to just search for a time.
>

If I understand your question correctly, then this is handled
differently by different databases.

For example, mysql uses DATE_FORMAT/TIME_FORMAT, sqlite uses STRFTIME,
and PostgreSQL uses the powerful extract/to_char. See the manual for
your specific database on how to extract and format parts of the a
datetime column for use it in comparisons/queries.

From rails, you could specify this custom SQL as a :condition to find,
or use execute(sql).

The last time I needed similar functionality, I didn't find any built-in
methods to accomplish this in rails. Would like to know if one exists
and I somehow missed it.

hth,
ammar


From: Seebs on
On 2010-01-23, Morgan Morgan <nagromh(a)gmail.com> wrote:
> i have to count how many records are in a database that have a start
> time of 11:00 for an entire year. the problem is, i can't seem to find
> out how to coax rails into ignoring the date to just search for a time.

The simplest solution: Do that part of the check yourself, so just have
Rails hand you the whole query and you do the heavy lifting.

-s
--
Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam(a)seebs.net
http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures
http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated!
From: Morgan Morgan on
Ammar Ali wrote:
> Morgan Morgan wrote:
>> i have to count how many records are in a database that have a start
>> time of 11:00 for an entire year. the problem is, i can't seem to find
>> out how to coax rails into ignoring the date to just search for a time.
>>
>
> If I understand your question correctly, then this is handled
> differently by different databases.
>
> For example, mysql uses DATE_FORMAT/TIME_FORMAT, sqlite uses STRFTIME,
> and PostgreSQL uses the powerful extract/to_char. See the manual for
> your specific database on how to extract and format parts of the a
> datetime column for use it in comparisons/queries.
>
> From rails, you could specify this custom SQL as a :condition to find,
> or use execute(sql).
>
> The last time I needed similar functionality, I didn't find any built-in
> methods to accomplish this in rails. Would like to know if one exists
> and I somehow missed it.
>
> hth,
> ammar


from what i can tell it's not directly possible to search for a time
match without a full date/time. i'm already using sphinx for others
stuff and ended up using sphinx for this also. tried doing the search
for an entire year other ways but they were all stupidly slow. sphinx
is it
--
Posted via http://www.ruby-forum.com/.