Get Current Date – Different Ways Laravel Example

get current date and time laravel easy web programming
  • In Laravel Framework many of ways to get Current Date

In this article, we learn how to get current date in Laravel with an example

Using Carbon to get the current date in Laravel

Carbon is the API extension used for the DateTime format. Carbon provides many of ways to get current date and parse date and time in laravel
Carbon is an API extension for using the date and time. Carbon Parse method used to parse string-to-date and string-to-time in Laravel. Carbon Format provides many of format for changing the Date Time format in Laravel. Carbon is the most commonly used extension in Laravel framework.

#1 Get Current Date With Carbon::now()

use Illuminate\Support\Carbon; 

$currentDate = Carbon::now();
Output :-
carbon date

#2 Get Current Date With Carbon::today()

   use Illuminate\Support\Carbon; 
$currentDate = Carbon::today();

Output :-

carbon date

#3 Get Current Date With Date Function

$currentDate = date('d/m/y');

Output :-

12-04-22

#4 Get Current Month With Carbon Format

 use Illuminate\Support\Carbon; 
$currentMonth = Carbon::now()->format('F');
 

Output :-

December

#5 Get Current Day With Carbon Format

 use Illuminate\Support\Carbon; 
$currentDay = Carbon::now()->format('l');
 

Output :-

Sunday

#6 Get Current Year With Carbon Format

 use Illuminate\Support\Carbon; 
$currentYear = Carbon::now()->format('Y');
 

Output :-

2022

#How To Get Current Time in Laravel

#7 Get Current Time With Date Function

$currentTime = date('H:t:s');

Output :-

07:31:25

#8 Get Current Time With Carbon

$currentTime = Carbon::now()->format('H:t:s');
 

Output :-

07:31:04

Date Format In Carbon :-

Carbon::now()->format('y/m/d');
Carbon::now()->format('y-m-d');
Carbon::now()->format('m d y');
Carbon::now()->format('d/m/y H:i:s A');

Leave a Comment

Your email address will not be published. Required fields are marked *