I am trying to filer records based on date from created_at.
For this I am passing from_date and to_date from date-picker in Date Format (e.g. "%y/%m/%d").
Please help me with how to write query in the controller to fetch the records between dates.
@users = User.where(['created_at = ? and created_at = ?',from_date,to_date])
Thanks.
You can use the range syntax, looks cleaner:
@users = User.where(:created_at => start_date.to_time..end_date.to_time)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With