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

perkola's avatar

Retrieve records created at a specific date

I have a table with several records containing data over time. Each row has the default timestamp created_at and some data fields.

How can i retrieve all records from the table from a specific date, regardless of time? For example I would like to get all data records from 22nd march 2015.

The created_at field has values like 2015-03-22 14:13:52, 2015-03-22 14:23:52, 2015-03-22 14:33:52 and so on. Can I use some kind of wildcard for the seconds in my Eloquent query?.

0 likes
2 replies
JarekTkaczyk's avatar
Level 53

@perkola use raw date function and extract only date part

$query->whereRaw('date(created_at) = ?', [Carbon::today()]);
// or
$query->whereRaw('date(created_at) = ?', [date('Y-m-d')]);
// or
$query->where(DB::raw('date(created_at)'), Carbon::today());
4 likes
perkola's avatar

Thanks @JarekTkaczyk

I just replaced Carbon::today() with the variable containing the specific date and it works. Much appreciated!

1 like

Please or to participate in this conversation.