# How to do program in different way?

**URL:** <https://www.ruby-forum.com/t/how-to-do-program-in-different-way/234803>\
**Category:** Rails\
**Created:** [July 18, 2014, 9:50am UTC](https://www.ruby-forum.com/t/how-to-do-program-in-different-way/234803 "2014-07-18T09:50:38Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![alcina](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/a587f6/32.png) [@alcina](https://www.ruby-forum.com/u/alcina)\
**Post date:** [July 18, 2014, 9:50am UTC](https://www.ruby-forum.com/t/how-to-do-program-in-different-way/234803/1 "2014-07-18T09:50:38Z")

</div>

I am using Ruby 1.9.3 and Rails 3.2.16.

I written program to get data for each month and I have add search  
feature for month.

> > In Model:

def self.search(search)  
if search  
find(:all, :conditions =\> [‘month LIKE ?’, “%#{search}%”])  
else  
find(:all)  
end  
end

Now,Above program is only to get report for month.

I am trying to do program like if i enter day or month or year then  
also i should get data corresponding day or month or year.

I tried several ways but i am not getting correct one.

Could anyone help in this?

Kind regards.

---

<div class="post-metadata">

**Author:** ![jaimin26783](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/d78d45/32.png) [@jaimin26783](https://www.ruby-forum.com/u/jaimin26783)\
**Post date:** [July 18, 2014, 2:00pm UTC](https://www.ruby-forum.com/t/how-to-do-program-in-different-way/234803/2 "2014-07-18T14:00:07Z")

</div>

On Friday, 18 July 2014 03:51:23 UTC-4, [Ruby-Forum.com](http://Ruby-Forum.com) User wrote:

> ```
> find(:all, :conditions => ['month LIKE ?', "%#{search}%"])
> 
> ```
> 
> I am trying to do program like if i enter day or month or year then  
> also i should get data corresponding day or month or year.
> 
> I tried several ways but i am not getting correct one.

It’s hard to give much guidance without seeing the “several ways” or any  
details about your schema.

Why is “month” a string column? If you want to search by date range, it  
seems like a date column would be more useful.

For day + year reporting, how is that data stored?

–Matt J.

---

<div class="post-metadata">

**Author:** ![jaimin26783](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/d78d45/32.png) [@jaimin26783](https://www.ruby-forum.com/u/jaimin26783)\
**Post date:** [July 18, 2014, 3:07pm UTC](https://www.ruby-forum.com/t/how-to-do-program-in-different-way/234803/3 "2014-07-18T15:07:07Z")

</div>

Jaimin P. wrote in post #1152808:

Thank you for your reply.

I fixed just now. I can able to search to get data particularly for day  
or month or year.

Kind regards.

---

<div class="post-metadata">

**Author:** ![jaimin26783](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/d78d45/32.png) [@jaimin26783](https://www.ruby-forum.com/u/jaimin26783)\
**Post date:** [July 18, 2014, 2:54pm UTC](https://www.ruby-forum.com/t/how-to-do-program-in-different-way/234803/4 "2014-07-18T14:54:24Z")

</div>

> It’s hard to give much guidance without seeing the “several ways” or any  
> details about your schema.

> > Details of schema:

ActiveRecord::Schema.define(:version =\> 20140717071753) do

create\_table “quantities”, :force =\> true do |t|  
t.string “title”  
t.decimal “price”, :precision =\> 8, :scale =\> 2  
t.datetime “created\_at”, :null =\>  
false  
t.datetime “updated\_at”, :null =\>  
false  
t.string “day”  
t.string “month”  
t.string “year”  
end

end

> Why is “month” a string column? If you want to search by date range, it  
> seems like a date column would be more useful.

Yes, if i want to search by date then date column would be more useful.  
What i am trying to do is If i want to get data for particular month or  
day or year then How can i do it? I added search feature for searching.

Kind regards

---

<div class="post-metadata">

**Author:** ![jaimin26783](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/d78d45/32.png) [@jaimin26783](https://www.ruby-forum.com/u/jaimin26783)\
**Post date:** [July 18, 2014, 3:08pm UTC](https://www.ruby-forum.com/t/how-to-do-program-in-different-way/234803/5 "2014-07-18T15:08:18Z")

</div>

On Jul 18, 2014, at 6:54 AM, Jaimin P. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Yes, if i want to search by date then date column would be more useful.  
> What i am trying to do is If i want to get data for particular month or  
> day or year then How can i do it? I added search feature for searching.

You use date functions to find the dates of the first day of the month  
and the last day of the month, for instance, and search that range of  
dates.
