# Very brief

**URL:** <https://www.ruby-forum.com/t/very-brief/184064>\
**Category:** Rails\
**Created:** [February 24, 2010, 2:48pm UTC](https://www.ruby-forum.com/t/very-brief/184064 "2010-02-24T14:48:09Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![mercurius](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/c89c15/32.png) [@mercurius](https://www.ruby-forum.com/u/mercurius)\
**Post date:** [February 24, 2010, 2:48pm UTC](https://www.ruby-forum.com/t/very-brief/184064/1 "2010-02-24T14:48:09Z")

</div>

> @jobs = Job.find(:all, :conditions =\> “#{Date.parse(str=”#{closing\_date}")} \>= #{Date.today.strftime("%d/%m/%Y")}")

In the above instance, ‘closing\_date’ is a string. I want to ensure that  
only instances of Job where the closing date is greater than or equal to  
today’s date are pulled into an array.

Please can someone rectify this code; I’m not sure where it’s going  
wrong.

---

<div class="post-metadata">

**Author:** ![mercurius](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/c89c15/32.png) [@mercurius](https://www.ruby-forum.com/u/mercurius)\
**Post date:** [February 24, 2010, 3:27pm UTC](https://www.ruby-forum.com/t/very-brief/184064/2 "2010-02-24T15:27:14Z")

</div>

You should probably convert closing\_date to a datetime datatype in the  
DB if  
possible:

script/generate migration change\_closing\_date  
… in the migration …  
change\_column :jobs, :closing\_date, :datetime

Otherwise you might try:

# add ’ and consistent formating

@jobs = Job.find(:all, :conditions =\>  
“’#{Date.parse(str=”#{closing\_date}").to\_s(:db)}’ \>=  
‘#{Date.today.to\_s(:db)}’")

---

<div class="post-metadata">

**Author:** ![mercurius](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/c89c15/32.png) [@mercurius](https://www.ruby-forum.com/u/mercurius)\
**Post date:** [February 24, 2010, 3:41pm UTC](https://www.ruby-forum.com/t/very-brief/184064/3 "2010-02-24T15:41:17Z")

</div>

On 24 February 2010 14:25, ben wiseley [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> ‘#{Date.today.to\_s(:db)}’")

The biggest problem with this finder is that it’s not querying any  
table fields. You seem to be just saying “where ‘1 jan 2010’ \>= ‘1 jan  
2010’” (substitute appropriate values for closing date and current  
date).  
So essentially you’re writing a query that says “if closing day is  
today or greater, give me every record in the table, otherwise, don’t  
give me any”

> @jobs = Job.find(:all, :conditions =\> “jobs.closing\_date \>= ‘#{Date.today.to\_s(:db)}’”

this would at least be a starting point, as you’d then be  
interrogating the closing\_date field.

Go and have a play with different queries in your SQL console. When  
you know how the query should look to get the result you want, you  
should be able to translate the conditions from that into a Rails  
finder. Test it in IRB to get to a solution working.
