Reputation: 2492
This is my sql query I wont to convert into rails model query
sql : SELECT "vouchers".* FROM "vouchers" WHERE "vouchers"."business_id" = 31 AND '2014-08-20' between start_date and end_date;
My tried model query but this not working please help me to make it working
Voucher.where(["#{Date.today} BETWEEN ? AND ?",:start_date,:end_date])
Upvotes: 0
Views: 155
Reputation: 26
Model.where("DATE(created_at) > :today AND DATE(promoted_till_date) < :two_weeks", today: Date.today, two_weeks: Date.today+14.days)
Upvotes: 0
Reputation: 2973
Assuming that start_date and end_date are columns try this version
Voucher.where("current_date between start_date and end_date").where(business_id: 31)
Upvotes: 1
Reputation:
Try in this format:
data = ModelName.where("today >= from_date AND today <= to_date")
Upvotes: 2