如何使用 Sequel 获取当前月份 [英] How to get the current month with Sequel
本文介绍了如何使用 Sequel 获取当前月份的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想用 Sequel 恢复当月的条目列表.
I would like recover a list of entries for the current month with Sequel.
我试过了:
Entry.where(:date >= Date.month).sum(:duration)
或
Entry.where(:date.like('%/06/2013')).sum(:duration)
和其他方式,但它们似乎都不起作用.
and other ways, but none of them seemed to work.
推荐答案
如果您想要当前月份和当前年份的所有条目,使用范围可能是最简单的:
If you want all entries the current month and the current year, it's probably easiest to use a range:
d = Date.today
Entry.where(:date=> Date.new(d.year, d.month)...(Date.new(d.year, d.month) >> 1)).sum(:duration)
如果您想要任何年份的当前月份,Sequel 已内置对此的支持:
If you want the current month in any year, Sequel has built in support for this:
Entry.where(Sequel.extract(:month, :date) => Date.today.month).sum(:duration)
这篇关于如何使用 Sequel 获取当前月份的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文