Carbon Add Minutes In Laravel

WebSolutionStuff | Dec-11-2020 | Categories : Laravel

Today we will see example of carbon add minutes in laravel, here i will give you simple example of laravel carbon add minutes, carbon provides many function like addMinute(), addMinute() to add minute in laravel.

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.

 

addMinute() Example

 

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

 

addMinutes() Example

 

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

 

Featured Post




Follow us
facebooklogo github instagram twitter