How to Get Current Date Time and Day in Laravel - TechvBlogs

How to Get Current Date Time and Day in Laravel

In this article, You will learn How to Get Current Date Time and Day in Laravel.


Smit Pipaliya - Author - TechvBlogs
Smit Pipaliya
 

9 months ago

TechvBlogs - Google News

This post will give you an example of laravel carbon getting the current date time. I would like to share with you the laravel carbon current timestamp. You will learn laravel carbon's current date. If you want to see an example of laravel carbon getting current year, then you are in the right place. Here, Creating a primary example of laravel carbon get the 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 DateTimeController extends Controller
{
    /**
     * Write code on Method
     *
     * @return response()
     */

    public function index()
    {
        $todayDate = Carbon::now();
        dd($todayDate);
    }
}

Output:

Carbon\Carbon Object
(
    [date] => 2023-05-22 14:15:46.741123
    [timezone_type] => 3
    [timezone] => UTC
)

Laravel Carbon Current Date:

<?php
  
namespace App\Http\Controllers;
  
use Illuminate\Http\Request;
use Carbon\Carbon;
  
class DateTimeController extends Controller
{
    /**
     * Write code on Method
     *
     * @return response()
     */
    public function index()
    {
        $todayDate = Carbon::now()->format('Y-m-d');
        dd($todayDate);
    }
}

 Output:

2023-05-22

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:

14:15:46

Laravel Carbon Current Day/Month/Year:

<?php
  
namespace App\Http\Controllers;
  
use Illuminate\Http\Request;
use Carbon\Carbon;
  
class DateTimeController 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:

22
05
2023

Thank you for reading this article.

If you have any queries or doubts about this topic please feel free to contact us. We will try to reach you.

Comments (0)

Comment


Note: All Input Fields are required.