1

I have a model, Consultation, and it has two fields :date and :original_date. Is it possible to pull all consultations where :date is greater than one year after :original_date without looping through all consultations?

I tried something like this but it didn't work:

Consultation.where("date >= ?", self.original_date + 1.year)

1 Answer 1

1

If you're using Postgres you can do this

Consultation.where("date >= (original_date + INTERVAL '1 year')")

https://www.postgresql.org/docs/current/functions-datetime.html

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.