In my project I need to have ability ti add reports.
Adding a report user can choose date for placing his report. (not created_at)
I save this data in "Date":DataTime - format column(2012-03-24T00:00:00+00:00)
User selects date from datepicker and than i parse it with DateTime.parse(2012-03-24)
and than save to DB.
Than user via datepicker selects a month.
How can I correctly perform a query to find all records for perticular month?
Is there any method to find by month?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
No. You should calculate margin dates and use :date => range
(it will create sql BETWEEN query). For example:
month = params[:month].to_i
date_a = DateTime.new Date.today.year, month, 1
date_b = (date_a >> 1) + 1 # will add a month and a day
Page.all :updated_at => date_a..date_b