Laravel Carbon Add Minutes Example Tutorial

Aug 14, 2021 . Admin



Hi Artisan,

Today, In this Article, i will explain how to add minutes in laravel using carbon in laravel so it can easy to use in laravel app.

So,if you needed to integrate one minute or more minutes you can use carbon in laravel. carbon provide inbuilt function addMinute()

and addMinutes() method to add minutes on carbon date object. so let's see some examples to add minute and minutes.

Here, I will give you a full example of how to add minutes in laravel using carbon in laravel. so follow my example code and you can use your laravel application to copy that code.

Example : 1
<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Carbon\Carbon;

class HomeController extends Controller
{
    /**
     * laravel carbon add minute..
     *
     * @return string
    */
    public function index()
    {
        $currentDateTime = Carbon::now();
        $newDateTime = Carbon::now()->addMinute();

        // echo "<pre />";
        print_r($currentDateTime);
        print_r($newDateTime);
    }

}
Output
Carbon\Carbon Object

(
    [date] => 2021-08-14 04:58:56.906490

    [timezone_type] => 3

    [timezone] => UTC
)

Carbon\Carbon Object

(
    [date] => 2021-08-14 04:59:56.906494

    [timezone_type] => 3

    [timezone] => UTC
)
Example : 2
<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Carbon\Carbon;

class HomeController extends Controller
{
    /**
     * laravel carbon add minutes..
     *
     * @return string
    */
    public function index()
    {
        $currentDateTime = Carbon::now();
        $newDateTime = Carbon::now()->addMinutes(5);

        // echo "<pre />";
        print_r($currentDateTime);
        print_r($newDateTime);
    }

}
Output
Carbon\Carbon Object

(
    [date] => 2021-08-14 05:01:09.629989

    [timezone_type] => 3

    [timezone] => UTC
)

Carbon\Carbon Object

(
    [date] => 2021-08-14 05:06:09.629994

    [timezone_type] => 3

    [timezone] => UTC
)

I Hope It Will Help You..

#Laravel 8 #Laravel