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

By Hardik Savani April 16, 2024 Category : Laravel

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, laravel 9, laravel 10 and laravel 11 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 App\Http\Controllers;

use Illuminate\Http\Request;

use App\Models\User;

use Carbon\Carbon;

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...

Tags :
Shares