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

LaraBABA's avatar

Stuck with Eloquent Date where() clause

Hi all,

I bet it is stupid to solve but I am actually stuck.

I am trying to run this:

        $today = Carbon::now();
        logger($today); //  2022-11-04 15:19:49
        $page = Event::where('slug', $slug)->where('active_from', '>=', $today)->first();

The where clause is not working when I add "'>=' , $today" It seems that this date:

2022-11-04 15:19:49

Is not being accepted in the where clause.

The column 'active_from' has the date time registered as(which seems to be the same format):

2022-11-07 14:43:00

I should get a result but receive NULL each time, unless I remove this where clause.

Any idea why please?

Thank you

0 likes
6 replies
tykus's avatar
$today = Carbon::now();
$page = Event::where('slug', $slug)->whereDate('active_from', '>=', $today)->first();
1 like
LaraBABA's avatar

Thanks @tykus ,I am still having a NULL result.

But I have noticed that if I output the $page request without the whereDate(). The date in the results shows as:

"from_date":"2022-10-27T21:22:00.000000Z",
Sinnbeck's avatar

What is the column type of active_from ?

1 like
LaraBABA's avatar

Oh my.....the code is actually fine, it is returning NULL because my actual selected date is < today!

I mixed up 2 columns because of a routing issue, I thought it was pulling the id1 when the code was pulling the id2.

Sorry sorry!!!

Please or to participate in this conversation.