Laravel Carbon Subtract Minutes Example

Laravel Carbon Subtract Minutes Example

Hello friends, Today i will explain Laravel Carbon Subtract Minutes Example. In this example you will show how to Subtract minutes in laravel using carbon.

In this example i will use carbon for Sub Minute and Sub Minutes in laravel. Carbon provide inbuilt function subMinute() and subMinutes() method to sub minutes on carbon date object. So let’s following my example to substract minute in your application.

Laravel Carbon Subtract Minute to Current Time

In this example we subtract one minute to time in laravel. So let’s following example.

<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Carbon\Carbon;
class HomeController extends Controller
{
    /**
     * laravel carbon sub-minute...
     *
     * @return string
    */
    public function index()
    {
        $currentDateTime = Carbon::now();
        $newDateTime = Carbon::now()->subMinute();
        // echo "<pre />";
        print_r($currentDateTime);
        print_r($newDateTime);
    }
}

Laravel Carbon Subtract Minutes to Current Time

In this example we subtract number of minute to time in laravel. So let’s following example.

<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Carbon\Carbon;
class HomeController extends Controller
{
    /**
     * laravel carbon sub minutes...
     *
     * @return string
    */
    public function index()
    {
        $currentDateTime = Carbon::now();
        $newDateTime = Carbon::now()->subMinutes(2);
        // echo "<pre />";
        print_r($currentDateTime);
        print_r($newDateTime);
    }
}

I hope you understand of Carbon Subtract Minutes and it can help you…

Read Also :  Laravel Insert Data using Create Method