Skip to content
Advertisement

PHP Carbon / Laravel Eloquent – Check if DateTime value is for the current day

I am working on a booking system and need to select only the records where a certain field is for today. Not today and in the future, but only today.

The query currently is:

$advancedBookings = Booking::where('type', 2)
    ->whereNull('estimated_booking_time')
    ->where('requested_booking_time', ?????);

$advancedBookings->get();

The requested_booking_time is the field that I wish to be checked, the date stored is in this format:

2017-08-23 08:00:00

So I want to only select rows that are on the same day as the current day.

Advertisement

Answer

As i understand, you want that records which is created today; then just get the today’s date.

$today = date("Y-m-d");

now your query is like this.

$advancedBookings = Booking::where('type', 2)
    ->whereNull('estimated_booking_time')
    ->where('requested_booking_time', $today)->get();
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement