ruby - Unable to extract Model Data Using created_at in rails 2 application -


@versions = version.find_all_by_created_at(2015-05-07) @versions = [] 

datatype created_at(datetime)

please want extract data passing date model .

i think simple if want current date can use date.today

version.where(created_at: date.today.beginning_of_day..date.today.end_of_day) 

otherwise @davidesantangelo has mentioned fine, except using parsed "date" variable, can use "date.beginning_of_day" e.g.

selectdate = date.parse('2015-05-07')  version.where(created_at: selectdate.beginning_of_day..selectdate.end_of_day) 

that form query this:

select "versions".* "versions"  ("versions"."created_at"  between '2015-04-28 00:00:00.000000' , '2015-04-28 23:59:59.999999') 

and without "beginning_of_day" have query

select "users".* "users"  ("users"."created_at"  between '2015-04-28' , '2015-04-28 23:59:59.999999') 

so prefer beginning_of_day.


Comments