Forked from agungyuliaji/activerecord-find-by-year-day-or-month-on-a-date-field.rb
Created
July 20, 2022 17:07
-
-
Save scratchoo/d9f8ed6916fe26fca7e02c2d1653166b to your computer and use it in GitHub Desktop.
ActiveRecord Find By Year, Day or Month on a Date field
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Model.where(:date_column => date) | |
Model.where('extract(year from date_column) = ?', desired_year) | |
Model.where('extract(month from date_column) = ?', desired_month) | |
Model.where('extract(day from date_column) = ?', desired_day_of_month) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment