How to Use Laravel 10 Carbon addMinutes() Method: A Practical Example?

05-Jan-2024

.

Admin

How to Use Laravel 10 Carbon addMinutes() Method: A Practical Example?

Hello Dev,

This article will provide an example of how to use the Laravel 10 carbon add minutes () method: a practical example. I’m going to show you about Laravel carbon addminutes() - morioh. We will look at an example of the Laravel 10 carbon add minutes tutorial with example. In this article, we will implement a carbon add minutes in Laravel 10 example. Follow the below tutorial step of carbon add minutes in the Laravel example.

You can add minutes to the current date using Carbon in Laravel 6, Laravel 7, Laravel 8, Laravel 9, and Laravel 10 versions.

If you need to add a minute or multiple minutes to date, you can leverage Carbon in Laravel. Carbon provides the addMinute() and addMinutes() methods for manipulating date objects. Let's explore some examples of adding minutes, subtracting minutes, and even handling years within a date.

Let's explore an example.

Example 1: Add Minute


<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use Carbon\Carbon;

class SignaturePadController extends Controller

{

/**

* Write code on Method

*

* @return response()

*/

public function index()

{

$currentDateTime = Carbon::now();

$newDateTime = Carbon::now()->addMinute();

print_r($currentDateTime);

print_r($newDateTime);

}

}

Output

Carbon\Carbon Object

(

[date] => 2020-11-05 04:29:35.435461

[timezone_type] => 3

[timezone] => UTC

)

Carbon\Carbon Object

(

[date] => 2020-11-05 04:30:35.435461

[timezone_type] => 3

[timezone] => UTC

)

Example 2: Add Minutes

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use Carbon\Carbon;

class SignaturePadController extends Controller

{

/**

* Write code on Method

*

* @return response()

*/

public function index()

{

$currentDateTime = Carbon::now();

$newDateTime = Carbon::now()->addMinutes(5);

print_r($currentDateTime);

print_r($newDateTime);

}

}

Output

Carbon\Carbon Object

(

[date] => 2020-11-05 04:29:35.435461

[timezone_type] => 3

[timezone] => UTC

)

Carbon\Carbon Object

(

[date] => 2020-11-05 04:34:35.435461

[timezone_type] => 3

[timezone] => UTC

)

Example 3: Sub Minute

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use Carbon\Carbon;

class SignaturePadController extends Controller

{

/**

* Write code on Method

*

* @return response()

*/

public function index()

{

$currentDateTime = Carbon::now();

$newDateTime = Carbon::now()->subMinute();

print_r($currentDateTime);

print_r($newDateTime);

}

}

Output

Carbon\Carbon Object

(

[date] => 2020-11-05 04:32:50.651145

[timezone_type] => 3

[timezone] => UTC

)

Carbon\Carbon Object

(

[date] => 2020-11-05 04:31:50.651145

[timezone_type] => 3

[timezone] => UTC

)

Example 4: Sub Minutes

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use Carbon\Carbon;

class SignaturePadController extends Controller

{

/**

* Write code on Method

*

* @return response()

*/

public function index()

{

$currentDateTime = Carbon::now();

$newDateTime = Carbon::now()->subMinutes(2);

print_r($currentDateTime);

print_r($newDateTime);

}

}

Output

Carbon\Carbon Object

(

[date] => 2020-11-05 04:29:51.651667

[timezone_type] => 3

[timezone] => UTC

)

Carbon\Carbon Object

(

[date] => 2020-11-05 04:27:51.651667

[timezone_type] => 3

[timezone] => UTC

)

I hope it can help you...

#Laravel 10