Laravel Carbon Get Current Date Time Example

By Hardik Savani November 24, 2020 Category : Laravel

Hi All,

This post will give you example of laravel carbon get current date time. i would like to share with you laravel carbon current timestamp. you will learn laravel carbon current date. if you want to see example of laravel carbon get current year then you are a right place. Here, Creating a basic example of laravel carbon get current day.

Let's see one by one example:

Laravel Carbon Current Date Time:

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use Carbon\Carbon;

class SignaturePadController extends Controller

{

/**

* Write code on Method

*

* @return response()

*/

public function index()

{

$todayDate = Carbon::now();

dd($todayDate);

}

}

Output:

Carbon\Carbon Object

(

[date] => 2020-11-24 03:54:24.408223

[timezone_type] => 3

[timezone] => UTC

)

Laravel Carbon Current Date:

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use Carbon\Carbon;

class SignaturePadController extends Controller

{

/**

* Write code on Method

*

* @return response()

*/

public function index()

{

$todayDate = Carbon::now()->format('Y-m-d');

dd($todayDate);

}

}

Output:

2020-11-24

Laravel Carbon Current Time:

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use Carbon\Carbon;

class SignaturePadController extends Controller

{

/**

* Write code on Method

*

* @return response()

*/

public function index()

{

$todayDate = Carbon::now()->format('H:i:m');

dd($todayDate);

}

}

Output:

04:00:11

Laravel Carbon Current Day/Month/Year:

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use Carbon\Carbon;

class SignaturePadController extends Controller

{

/**

* Write code on Method

*

* @return response()

*/

public function index()

{

$day = Carbon::now()->format('d');

$month = Carbon::now()->format('m');

$year = Carbon::now()->format('Y');

}

}

Output:

24

11

2020

I hope it can help you...

Tags :