开发者

Find by date by attributes

I have calendar and even开发者_StackOverflow社区ts. How can I find events by day? Event have created_at attribute. created_at have year, month, day. hour, minutes. How can I find only by day?


You could do something like this:

day = "04" #i.e. 4th of the month
@users = User.where("strftime('%d', created_at)  = ?", day)

If you want to specify the month also then you can do this:

month = "06" # i.e. June
day = "04"
@users = User.where("strftime('%d', created_at)  = ? AND strftime('%m', created_at) = ?", day, month)

Although there probably is a better way to do this.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜