Laravel 10 Carbon Check If Date Is Greater Than Other Date

02-Jun-2023

.

Admin

Laravel 10 Carbon Check If Date Is Greater Than Other Date

Hi Guys,

Today, In this example I will explain to you how to check if the date is greater than another date in Laravel 10. so it can be easy to use in Laravel 10 app.

So, laravel 10 carbon check if a date is greater than other dates, laravel 10 carbon compare two dates, laravel 10 carbon check if the current date is greater than another date, laravel 10 carbon check if a date is bigger than today.

Here, I will give you a full example of how to Laravel 10 carbon check if a date is greater than another date so follow my all steps.

Download Laravel


Let us begin the tutorial by installing a new Laravel application. if you have already created the project, then skip the following step.

composer create-project laravel/laravel example-app

Example : 1

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use Carbon\Carbon;

class HomeController extends Controller

{

/**

* laravel 10 carbon check date...

*

* @return string

*/

public function index()

{

$otherDate = Carbon::now()->subMinutes(5);

$nowDate = Carbon::now();

$result = $nowDate->gt($otherDate);

var_dump($result);

}

}

Output:

bool(true)

Example : 2

Here, In this example, we are not set the date between two dates so it will return to false.

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use Carbon\Carbon;

class HomeController extends Controller

{

/**

* laravel 10 carbon check date...

*

* @return string

*/

public function index()

{

$otherDate = Carbon::now()->subMinutes(5);

$nowDate = Carbon::now();

$result = $otherDate->gt($nowDate);

var_dump($result);

}

}

Output:

bool(false)

It will help you...

#Laravel 10