Laravel Carbon addMinutes() | Laravel Carbon Add Minutes Example

By Hardik Savani | November 10, 2020 | Category : Laravel


Hi,

In this tutorial we will go over the demonstration of laravel carbon add minute. we will help you to give example of laravel carbon add minutes. we will help you to give example of laravel carbon add 1 minute. this example will help you laravel carbon addMinutes(). Let's get started with add minutes to date in laravel.

You can add minutes on current date using carbon in laravel 6, laravel 7 and laravel 8 version.

If you need to add minute or more minutes in date then you can use carbon in laravel. carbon provide addMinute() and addMinutes() method to add minutes on carbon date object. so let's see some examples to adding minute and minutes and sub minute and years from date.

Let's see 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...



Tags : Carbon Laravel


Hardik Savani
My name is Hardik Savani. I'm a full-stack developer, entrepreneur and owner of Aatman Infotech. I live in India and I love to write tutorials and tips that can help to other artisan. I am a big fan of PHP, Javascript, JQuery, Laravel, Codeigniter, VueJS, AngularJS and Bootstrap from the early stage.
Follow Me: Github Twitter
***Do you want me hire for your Project Work? Then Contact US.

We are Recommending you: