I have these 2 lines which may help you:
>>> Carbon\Carbon::parse( 'Nov 21' )->day
=> 21
>>> collect([15, 18, 10, 20, 32])->filter(function($i) { return $i < 21; })->max()
=> 20
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
How to get a previous record or data using the specific date?
Example:
If I have a data from Nov 20 - 23, I want the data of Nov 19 (which is Monday) to be the the last data before it. So ...
Previous Dates: ['Nov 8', 'Nov 9', 'Nov 14', 'Nov 15', 'Nov 16']
Previous Data: [11, 20, 30, 13, 15]
Dates: ['Nov 19', 'Nov 20', 'Nov 21', 'Nov 22', 'Nov 23']
Data:
[15, 18, 10, 20, 32]
The 15 in Data should be the previous record.
Support Reference (Stackoverflow):
Please or to participate in this conversation.