# Trouble adding date query variable

**URL:** <https://www.ruby-forum.com/t/trouble-adding-date-query-variable/130047>\
**Category:** Ruby\
**Created:** [February 24, 2008, 10:25pm UTC](https://www.ruby-forum.com/t/trouble-adding-date-query-variable/130047 "2008-02-24T22:25:55Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![laredotornado](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/9dc877/32.png) [@laredotornado](https://www.ruby-forum.com/u/laredotornado)\
**Post date:** [February 24, 2008, 10:25pm UTC](https://www.ruby-forum.com/t/trouble-adding-date-query-variable/130047/1 "2008-02-24T22:25:55Z")

</div>

Hi,

I’m trying to build a search form with a date input field, displayed  
like this:

\<%= date\_select(:purchase\_date, params[:purchase\_date]) %\>

But I’m having trouble adding the criteria in my controller. So far,  
I have:

```
            if !search[:purchase_date].blank?
                    conditions << 'purchase_date >= ?'
                    conditions << "#{search[:purchase_date]}"
            end
            find(:all, :conditions => conditions, :page => {:size

```

=\> page\_size, :current =\> page\_num} )

But the query gets run in a weird way, below:

SELECT count(ec\_orders.id) AS count\_ec\_orders\_id FROM `ec_orders`  
WHERE purchase\_date \>= ‘(3i)24(1i)2006(2i)2’)

What is the right way to get the date to be displayed normally in the  
SQL query? - Dave

---

<div class="post-metadata">

**Author:** ![laredotornado](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/9dc877/32.png) [@laredotornado](https://www.ruby-forum.com/u/laredotornado)\
**Post date:** [February 25, 2008, 3:25pm UTC](https://www.ruby-forum.com/t/trouble-adding-date-query-variable/130047/2 "2008-02-25T15:25:27Z")

</div>

laredotornado wrote:

> Hi,
> 
> I’m trying to build a search form with a date input field, displayed  
> like this:
> 
> \<%= date\_select(:purchase\_date, params[:purchase\_date]) %\>
> 
> But I’m having trouble adding the criteria in my controller. So far,  
> I have:
> 
> ```
> if !search[:purchase_date].blank?
> conditions << 'purchase_date >= ?'
> conditions << "#{search[:purchase_date]}"
> end
> find(:all, :conditions => conditions, :page => {:size
> 
> ```
> 
> =\> page\_size, :current =\> page\_num} )
> 
> But the query gets run in a weird way, below:
> 
> SELECT count(ec\_orders.id) AS count\_ec\_orders\_id FROM `ec_orders`  
> WHERE purchase\_date \>= ‘(3i)24(1i)2006(2i)2’)
> 
> What is the right way to get the date to be displayed normally in the  
> SQL query? - Dave

conditions =\> [“purchase\_date \>= ?”, search[:purchase\_date].to\_s(:db)]

hth

ilan
