Reputation: 95
I would like to convert type of created_at inside query
passenger = Passenger.where("created_at.to_date = ?", Date.yesterday)
The .to_date method is not working. Can it be done? Is there a workaround for this
Upvotes: 0
Views: 56
Reputation: 151
The proper solution will be is:
passengers = Passenger.where("DATE(created_at) = DATE(?)", Date.yesterday)
But if you need take only one, you can use
passenger = Passenger.find_by(created_at: Date.yesterday)
I wrote it because name of variable was not plural
Upvotes: -1
Reputation: 2040
passenger = Passenger.where("DATE(created_at) = ?", Date.yesterday)
Upvotes: 1