In this post, we will learn how you can get the current date, time and day in the laravel.
Lets get started!
We will be using laravel “now” helper function which in the backend calls the carbon library. So “now” has the access to all the carbon library functions.
Table of Contents
Getting Current Date In Laravel
So to get the current Date in laravel, we will call the “now” helper function followed by format.
{{now()->format('d-m-Y')}}
This will give us the current date in dd-mm-yyyy format where:
- d stands for day
- m for month
- Y for year
So the output will be like this:
25-03-2022
Getting Current Time In Laravel
To get the current time with hours, minutes and seconds, we will again call the “now” helper function with format.
{{now()->format('H:i:s')}}
This will give us time in 24 hours where:
- H stand for Hour
- i stands for minutes
- s for seconds
So the output will be like this:
17:25:05
Getting Current Day in Laravel
Now to get the current day or week day in laravel, we have to call again “now” helper function followed by format.
{{ now()->format('l') }}
This will give weekday. So the Output would be:
Monday
Conclusion
Hope you have learned today, how to get the current date, time and day in laravel. If you have any questions, please ask in the comments below.
See you in the next one.
Write a Reply or Comment