# Query realated to date\_select tag

**URL:** <https://www.ruby-forum.com/t/query-realated-to-date-select-tag/132062>\
**Category:** Rails\
**Created:** [March 16, 2008, 8:42am UTC](https://www.ruby-forum.com/t/query-realated-to-date-select-tag/132062 "2008-03-16T08:42:44Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![subhadip](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/3d9bf3/32.png) [@subhadip](https://www.ruby-forum.com/u/subhadip)\
**Post date:** [March 16, 2008, 8:42am UTC](https://www.ruby-forum.com/t/query-realated-to-date-select-tag/132062/1 "2008-03-16T08:42:44Z")

</div>

i have two date select tag like:in view  
\<%= date\_select:date1,:order=\>[:year,:month,:date] %\>  
\<%= date\_select:date2,:order=\>[:year,:month,:date] %\>  
and in controller i write  
@infos = Info.find(:all, :conditions =\> [“dt between ? and ?”,  
params[:date1], params[:date2]])  
but the query can;t execute.the error is  
You have an error in your SQL syntax; check the manual that corresponds  
to your MySQL server version for the right syntax to use near ‘’— \n-  
orderyearmonthdate(2i)\n- “3”\n’,’— \n- orderyearmonthdate(3i)\n- ’  
at line 1: SELECT \* FROM `infos` WHERE (dt between ‘— \n-  
orderyearmonthdate(1i)\n- “2008”\n’,’— \n- orderyearmonthdate(2i)\n-  
“3”\n’,’— \n- orderyearmonthdate(3i)\n- “16”\n’ and ‘— \n-  
orderyearmonthdate(1i)\n- “2008”\n’,’— \n- orderyearmonthdate(2i)\n-  
“3”\n’,’— \n- orderyearmonthdate(3i)\n- “16”\n’)  
what should i do?  
please help…very urgent…  
please provide :simple code::

---

<div class="post-metadata">

**Author:** ![subhadip](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/3d9bf3/32.png) [@subhadip](https://www.ruby-forum.com/u/subhadip)\
**Post date:** [March 16, 2008, 12:00pm UTC](https://www.ruby-forum.com/t/query-realated-to-date-select-tag/132062/2 "2008-03-16T12:00:36Z")

</div>

On Mar 16, 7:42 am, Subhadip Chakraborty \<rails-mailing-l…@andreas-  
[s.net](http://s.net)\> wrote:

> i have two date select tag like:in view  
> \<%= date\_select:date1,:order=\>[:year,:month,:date] %\>  
> \<%= date\_select:date2,:order=\>[:year,:month,:date] %\>  
> and in controller i write  
> @infos = Info.find(:all, :conditions =\> [“dt between ? and ?”,  
> params[:date1], params[:date2]])  
> but the query can;t execute.the error is  
> [snip]  
> what should i do?

You need to use select\_date instead of date\_select (date\_select is  
like text\_field and so on: it expects to be used to update or create  
an instance of an ActiveRecord object. select\_date is more like  
text\_field\_tag). Then you need to realise (look at your logs) that the  
date is submitted as its indidual components (ie year, month, day) and  
you need to turn that back into an actual date or time (eg via  
Date::civil or Time.now).

Fred
