开发者

Find by date by attributes

开发者 https://www.devze.com 2023-03-10 14:56 出处:网络
I have calendar and even开发者_StackOverflow社区ts. How can I find events by day? Event have created_at attribute.

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

精彩评论

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

关注公众号