Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

firstpointdev's avatar

Database date range comparison

gone

0 likes
2 replies
Duffleman's avatar

What kind of database are you using? And can you confirm the layout of your database? Do you have two columns named 'fromDate' and 'toDate'?

If the column is set to the date type, then you should be able to use:

$formattedFromDate = $newFromDate->format('Y-m-d');
$formattedToDate = $newToDate->format('Y-m-d');

$query->whereBetween('date', [$formattedFromDate, $formattedToDate]);

This is assuming you have a column in your database called date.

manticore's avatar

What would you do if the database had multiple rows with fromDate column and toDate column?

Please or to participate in this conversation.