Drainer Channel
Drainer Channel

Reputation: 13

How check range beetwen to dates and make comparison in sql on ruby?

.joins(:residence) .where('(custom_services.date_from - ?) <= 1', Date.today)wrong attempt

Does anyone know how to correctly implement a check the difference between the date in custom_services.date_from and today's is less than or equal to one day(in the screenshot, one of the attempts is not correct)

Upvotes: 0

Views: 48

Answers (3)

mechnicov
mechnicov

Reputation: 15258

Using Date.tomorrow and beginless range:

.where(date_from: ..Date.tomorrow)

if need to specify table name

.where('custom_services.date_from': ..Date.tomorrow)

Upvotes: 2

jojogis
jojogis

Reputation: 16

you can just use

.where('custom_services.date_from <= ?', Date.today + 1.day)

Upvotes: 0

Lutfi Fitroh Hadi
Lutfi Fitroh Hadi

Reputation: 169

Can you use something like this?

where("DATEDIFF(custom_services.date_from, ?) <= 1", Date.today)

Upvotes: 0

Related Questions