So you want the first record where the effective date is less than or equal to the given date?
Model::query()
->whereDate('effective_date', '<=', $currentDate)
->orderBy('effective_date', 'desc')
->first()
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hello,
I have a particular query i'm trying to solve regarding multiple dates.
I have a pricing table, and in that table each price has an effective date e.g.
ID Price Currency Effective Date
1 | 9.99 | GBP | 2022-09-01
2 | 10.99 | GBP | 2022-09-10
3 | 11.99 | GBP | 2022-09-20
What i want is to show the price that is currently in scope,
So if the date today was 2nd September, then the price that comes first is 9.99.
If the date was then 10th September then the result will return 2 result and the price 10.99 becomes active and the price 9.99 drops off because that date is succeeded by row 2
Then if the date was then 20th September then the result will return 1 result and the price is 11.99.
Anyone know how i can achieve this?
So far i'm ordering the query by effective date so that it's at least in the correct order, but if the date was 10th September then the first row will still show.
thanks!!
Please or to participate in this conversation.