Carbon Add Minutes In Laravel Example

In this tutorial, we will see an example of carbon add minutes in laravel, here I will give you a simple example of laravel carbon add minutes, carbon provides many function like addMinute(), addMinutes() to add minute in laravel 8. Using the carbon addMinute() or addMinutes() function you can change the minutes in the date in laravel 8.

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

So, let's see an example of laravel 8 carbon add minutes to date or add minutes using carbon in laravel 8.

addMinute() Example

The carbon addMinute() function is used to add the minute on a date. So, here I will give you an example of the current date to add a minute.

<?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 : 

Current Date and Time : 2022-01-16 09:40:29
Current Date with Add Minute : 2022-01-16 09:41:29

 

 

addMinutes() Example

The Carbon addMinutes() function is used to add minutes as per your requirements on the date. So, here I will give you an example of the current date to add 10 minutes.

<?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 : 

Current Date and Time : 2022-01-16 09:42:11
Current Date with Add Minutes : 2022-01-16 09:52:11

 


You might also like :

techsolutionstuff

Techsolutionstuff | The Complete Guide

I'm a software engineer and the founder of techsolutionstuff.com. Hailing from India, I craft articles, tutorials, tricks, and tips to aid developers. Explore Laravel, PHP, MySQL, jQuery, Bootstrap, Node.js, Vue.js, and AngularJS in our tech stack.

RECOMMENDED POSTS

FEATURE POSTS