E
E
eldar_web2015-12-09 19:12:12
Ruby on Rails
eldar_web, 2015-12-09 19:12:12

How can Ruby on Rails group data from a model by a specific time (month)?

For example, there is a User model (it has a standard field :created_at).
So is it possible to find out the number of users in December, for example?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dima, 2015-12-09
@eldar_web

It is possible like this:

User.where(created_at: Date.parse('December')...Date.parse('December')+1.month).count

P
Pavel Grudinkin, 2015-12-09
@Hunt666

User.where("strftime('%m', created_at) = ?", '12').count
for sqlite

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question