0

I started code rails recently and I need to figure out this problem.

%td
  = Ahoy::Event.where(name: "viewed_brochure").where_properties(brochure_id: brochure.id, time: like 'Mon%').count

this should be show the number of Mondays in database. But it doesn't work and give syntax error.

I wonder how to use like operator in this line.

Ahoy::Event.where(time: "2017-10-30 14:50:35.361999").where_properties(brochure_id: brochure.id).count

This line works fine but i need to use like operator or something similar.

Emre
  • 119
  • 2
  • 8

2 Answers2

0

You can try to use built in postgres function for that:

Ahoy::Event.where("EXTRACT(DOW FROM time) = 1").where_properties(brochure_id: brochure.id).count
Nikita Misharin
  • 1,961
  • 1
  • 11
  • 20
0
 Ahoy::Event.where("date_part('dow', time) = 1").count

This will return the count of all events created at Monday.You can add more filters.

Anton
  • 540
  • 3
  • 13