Skip to content
Advertisement

MySQL Date between query [closed]

Why BETWEEN '2020-02-22 00:00:00' AND '2020-02-22 23:59:59' is working (getting Data)?

AND why BETWEEN '2020-02-22' AND '2020-02-22' is not working (Not getting Data)?

Edited: Got it. I forgot to add date(created_at) instead of created_at

Advertisement

Answer

You may use the whereBetween method

It verifies that a column’s value is between two values.

Expl

$from = date('2018-01-01');
$to = date('2018-05-02');

Model::whereBetween('dateColumn', [$from, $to])->get();

Or

Model::where('dateColumn', '>=', $from)->where('dateColumn', '<=', $to)->get();
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement