# ActiveRecord and SQL SUBSTR

**URL:** <https://www.ruby-forum.com/t/activerecord-and-sql-substr/112514>\
**Category:** Rails\
**Created:** [August 20, 2007, 3:00pm UTC](https://www.ruby-forum.com/t/activerecord-and-sql-substr/112514 "2007-08-20T15:00:06Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![reacher](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/0ea827/32.png) [@reacher](https://www.ruby-forum.com/u/reacher)\
**Post date:** [August 20, 2007, 3:00pm UTC](https://www.ruby-forum.com/t/activerecord-and-sql-substr/112514/1 "2007-08-20T15:00:06Z")

</div>

In one of my tables, I have a column that holds a 13 digit number that  
comprises several pieces of information. digits 2-6 contain a date (2  
digits for year without century, and 3 digits for julian date). Using  
straight SQL, I can select based on todays date using this query:

SELET \* from t\_history where SUBSTR(ICN, 3, 5) = ‘07232’;

How can I translate this SUBSTR calculation into ActiveRecord’s find  
condition hash?

---

<div class="post-metadata">

**Author:** ![reacher](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/0ea827/32.png) [@reacher](https://www.ruby-forum.com/u/reacher)\
**Post date:** [August 20, 2007, 7:58pm UTC](https://www.ruby-forum.com/t/activerecord-and-sql-substr/112514/2 "2007-08-20T19:58:58Z")

</div>

I figured it out

History.find(:all, :conditions =\> [“SUBSTR(ICN, 3, 5) = ?”, “07232”])
