Laravel Carbon Add Seconds Example

Laravel Carbon Add Seconds Example

Hello friends, Today I will show Laravel Carbon Add Seconds Example. In this post i will discuss about of how to add seconds to date in laravel. We will step by step to add second to time in laravel. We will use laravel carbon for add seconds.

When you need to integrate one second or more seconds you can use carbon in laravel. Carbon provide inbuilt function addSecond() and addSeconds() function to add seconds on carbon date object.

Laravel Carbon Add Second

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

Laravel Carbon Add Seconds

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

I hope you understand of Laravel Carbon Add Second ant it can help you…

Read Also :  How Generate PDF From HTML In Laravel dompdf