Forum: Ruby on Rails Finding record between 2 dates

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
84161f131a41bf1b730a7a4fbfd9068d?d=identicon&s=25 Vaibhav Deshpande (vaibhavdeshpandemca)
on 2009-04-08 11:51
I am very new to ruby on rails programming,
I am using the oracle as my database,

In my project there r 2 text box fields and in first and second text
boxes i want the date field to be enter by the client and want to
display the record between those 2 dates how can i do the same, plz be
more specific

Thanks in advance,
Vaibhavi...

Not so good not so bad
1e44d920287c3e26c3d7080769b5ccb5?d=identicon&s=25 Jaryl Sim (Guest)
on 2009-04-08 16:57
(Received via mailing list)
You can do this very easily with a named scope in your model:

named_scope :between, lambda {|start_date, end_date| {:conditions =>
["created_at BETWEEN :start AND :end", {:start => start_date, :end =>
end_date}]}}

On Apr 8, 5:51 pm, Vaibhav Deshpande <rails-mailing-l...@andreas-
280b78a61a968391b7e07e912be102a8?d=identicon&s=25 Robert Walker (robert4723)
on 2009-04-08 18:07
Vaibhav Deshpande wrote:
> I am very new to ruby on rails programming,
> I am using the oracle as my database,
>
> In my project there r 2 text box fields and in first and second text
> boxes i want the date field to be enter by the client and want to
> display the record between those 2 dates how can i do the same, plz be
> more specific

I'm not sure if this is an issue or not, but note that Oracle's DATE
field is also used for storing DATETIME. Maybe the Rails Oracle adaptor
handles this properly, but I just wanted to mention it in case you see
weird behavior.

> I am using the oracle as my database,

P. S. I wish my application could use "The Oracle" as its database. It
would always get the correct response even if it doesn't know what to
ask. ;-)

http://www.imdb.com/character/ch0000765/
84161f131a41bf1b730a7a4fbfd9068d?d=identicon&s=25 Vaibhav Deshpande (vaibhavdeshpandemca)
on 2009-04-09 10:34
Robert Walker wrote:
> Vaibhav Deshpande wrote:
>> I am very new to ruby on rails programming,
>> I am using the oracle as my database,
>>
>> In my project there r 2 text box fields and in first and second text
>> boxes i want the date field to be enter by the client and want to
>> display the record between those 2 dates how can i do the same, plz be
>> more specific
>
> I'm not sure if this is an issue or not, but note that Oracle's DATE
> field is also used for storing DATETIME. Maybe the Rails Oracle adaptor
> handles this properly, but I just wanted to mention it in case you see
> weird behavior.
>
>> I am using the oracle as my database,
>
> P. S. I wish my application could use "The Oracle" as its database. It
> would always get the correct response even if it doesn't know what to
> ask. ;-)
>
> http://www.imdb.com/character/ch0000765/
I used @date2ss = Date2.find(:all, :conditions => "ID > '"+ @date1 +"'
and ID <'"+ @date2+"'") and it works..
thanks,
Vaibhavi
5772c599ccab3081e0fffb1d54f3b6de?d=identicon&s=25 Andrew Timberlake (andrewtimberlake)
on 2009-04-09 11:00
(Received via mailing list)
> I used @date2ss = Date2.find(:all, :conditions => "ID > '"+ @date1 +"'
> and ID <'"+ @date2+"'") and it works..
> thanks,
> Vaibhavi
> --

You can also use
Model.find(:all, :conditions => {:date => date1..date2})


Andrew Timberlake
http://ramblingsonrails.com
http://www.linkedin.com/in/andrewtimberlake

"I have never let my schooling interfere with my education" - Mark Twain
84161f131a41bf1b730a7a4fbfd9068d?d=identicon&s=25 Vaibhav Deshpande (vaibhavdeshpandemca)
on 2009-04-09 11:41
Andrew Timberlake wrote:
>> I used @date2ss = Date2.find(:all, :conditions => "ID > '"+ @date1 +"'
>> and ID <'"+ @date2+"'") and it works..
>> thanks,
>> Vaibhavi
>> --
>
> You can also use
> Model.find(:all, :conditions => {:date => date1..date2})
>
>
> Andrew Timberlake
> http://ramblingsonrails.com
> http://www.linkedin.com/in/andrewtimberlake
>
> "I have never let my schooling interfere with my education" - Mark Twain

Thanks,
This topic is locked and can not be replied to.