如何按月查找记录 Datamapper [英] How to find records by month Datamapper
问题描述
在我的项目中,我需要能够添加报告.添加报告的用户可以选择放置报告的日期.(未创建_at)我将此数据保存在日期"中:DataTime - 格式列(2012-03-24T00:00:00+00:00)用户从 datepicker 中选择日期,然后我用 DateTime.parse(2012-03-24)
解析它,然后保存到数据库.比用户通过日期选择器选择一个月.如何正确执行查询以查找特定月份的所有记录?有没有办法按月找?
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?
推荐答案
没有.您应该计算保证金日期并使用 :date =>;range
(它将创建 sql BETWEEN 查询).例如:
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
这篇关于如何按月查找记录 Datamapper的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!