Check Date is Today or Not in Laravel Using Carbon

Hello devs,

In this quick example, I will discuss how to check whether the date is today's date or not in laravel using carbon. Sometimes we need to check whether the requested date is today or not. I am here to show you that laravel carbon check if date is today. So if you don't know carbon check if date is today then this example is for you.

You will learn from this tutorial how to compare date with current date in laravel. This example will help you how to check if the date is today date in laravel. Laravel Carbon packages provide isToday() helper to check date is today or not. Let's see the very simple solution below:

 

app/Http/Controllers/DemoController.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.");
        }
  
    }
}

 

Read also: How to Convert Time Format AM PM with Laravel Carbon

 

Hope it can help you.

 

author-image
Facebook Github
A web enthusiastic, a self-motivated full-stack software engineer from Dhaka, Bangladesh with experience in developing applications using Laravel , React and Vue js