How to Check Date is Today’s Date or not in Laravel Carbon?

Hi,

This extensive guide will teach you laravel carbon check if date is today. let’s discuss about how to check date is today date in laravel. you will learn how to compare date with current date in laravel. This example will help you how to check if date is today date in laravel.

You can use these tips with laravel 6, laravel 7, laravel 8 and laravel 9 versions.

Laravel Carbon provides isToday() method to check date is today date or not. so let’s see the simple example below:

Example:

app/Http/Controllers/DemoController.php

<?php

namespace AppHttpControllers;

use IlluminateHttpRequest;

use AppModelsUser;

use CarbonCarbon;

class DemoController extends Controller

{

/**

* Write code on Method

*

* @return response()

*/

public function index(Request $request)

{

/* Laravel Carbon Check Date is Today */

$user = User::find(10);

if ($user->created_at->isToday()){

print("User Created Today.");

}

/* Laravel Carbon Check Date is Today 2 */

$date = Carbon::parse("2022-10-27");

if ($date->isToday()){

print("Date is Today.");

}

}

}

Output:

User Created Today.

Date is Today.

I hope it can help you…

Leave a Comment