Carbon Add Minutes In Laravel

Websolutionstuff | Dec-11-2020 | Categories : Laravel PHP

In this example, we will see carbon add minutes in laravel. Here we will give you a simple example of laravel carbon add minutes to date. Carbon provides many functions like addMinute() and  addMinute() to add minutes in laravel. You can add minute to the current date and time in laravel 6, laravel 7, and laravel 8. The addMinutes() function may require to passing the parameter of the number of minutes.

So, let's see how to add minutes to date in laravel 7/8 and laravel 7/8 add a minute to date using carbon

If we need to add a minute or more than one minute in date and time then you can use carbon in laravel. carbon provides the addMinute() and addMinutes() methods to add minutes to the carbon date object.

Carbon addMinute() Example

In this example, we will add minute to the current date and time using the carbon addMinute() function.

<?php
  
namespace App\Http\Controllers;
  
use Illuminate\Http\Request;
use Carbon\Carbon;
  
class DateController extends Controller
{
    public function index()
    {
        $currentDateTime = Carbon::now();
        $newDateTime = Carbon::now()->addMinute();
             
        print_r($currentDateTime);
        print_r($newDateTime);
    }
}

 

Output:

Carbon\Carbon Object
(
    [date] => 2020-12-09 09:45:30.376461

    [timezone_type] => 2

    [timezone] => GMT
)

Carbon\Carbon Object
(
    [date] => 2021-12-09 09:46:30.376461

    [timezone_type] => 2

    [timezone] => GMT
)

 

 

Carbon addMinutes() Example

In this example, we will add three minutes to the current date and time using the addMinutes() function.

<?php
  
namespace App\Http\Controllers;
  
use Illuminate\Http\Request;
use Carbon\Carbon;
  
class DateController extends Controller
{
    public function index()
    {
        $currentDateTime = Carbon::now();
        $newDateTime = Carbon::now()->addMinutes(3);
             
        print_r($currentDateTime);
        print_r($newDateTime);
    }
}
 

 

Output:

Carbon\Carbon Object
(
    [date] => 2020-12-09 09:46:32.406561

    [timezone_type] => 2

    [timezone] => GMT
)

Carbon\Carbon Object
(
    [date] => 2023-12-09 09:49:32.406561

    [timezone_type] => 2

    [timezone] => GMT
)

 


You might also like:

Recommended Post
Featured Post
How to Downgrade PHP 8.2 to 8.1 in Ubuntu
How to Downgrade PHP 8.2 to 8....

Hey there, I recently found myself in a situation where I needed to downgrade my PHP version from 8.2 to 8.1 on my Ubunt...

Read More

Nov-01-2023

Cron Job Scheduling In Laravel
Cron Job Scheduling In Laravel

In this article, we will see cron job scheduling in laravel. Many times we require to run some piece of code in a specif...

Read More

Sep-28-2020

How To Change Text In Laravel 9 Datatable
How To Change Text In Laravel...

Do you want to learn how to change text in a Laravel 9 Datatable? This blog post is your complete guide to mastering tex...

Read More

Jan-06-2023

Custom Toastr Notification In Laravel 9
Custom Toastr Notification In...

In this article, we will see a custom toastr notification in laravel 9. we will create a custom notification using HTML,...

Read More

Sep-23-2022