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

nitishdola's avatar

Compare only date with created at field

I have a table complains where created_at is a timestamp field. Now to get all the complaints received in a particular day, I need to compare date with the created_at field(datetime). To achieve this I wrote :

if(isset($_GET['date']) && $_GET['date'] != '') {
           $date = date('Y-m-d', strtotime($_GET['date']));
           $matchThese[DATE('complains.created_at')] = $date;
       }

But when I run the query, It shows an error with trying to compare

`2015-08-07T16:03:59+05:30201508pFridaypm03859`.`2015-08-07T16:03:59+05:30Fri, 07 Aug 2015 16:03:59 +0530Asia/Kolkatapm31Asia/Kolkata07_pm31` = 2015-08-20
0 likes
3 replies
phildawson's avatar

?

$complains = DB::table('complains')->where('created_at', 'like', '2015-08-20%')->get();
shanRamesh's avatar

try this

->where(DB::raw('CAST(created_at as date)'), '>=', $from) ->where(DB::raw(' CAST(created_at as date) '), '<=', $to);

1 like
ngaunje's avatar

This works for me. Thanks budy for sharing

Please or to participate in this conversation.