Posts Learn Components Snippets Categories Tags Tools About
/

How to get current Date, Time and Day in Laravel 8

Learn how to get the current date, time, and day in Laravel using the built-in helper function. Make use of these methods to easily get the right value

Created on Nov 14, 2021

13860 views

In Laravel, you can make use of the "now" helper function where behind the scene it's using carbon library to construct the date object. By default calling this helper function you will get the instance itself so if you want to get a specific date, format and etc you need to call the methods for each respective sue case.
<?php now();

Getting Current Date In Laravel


To get the current date you can call the "now()" helper function and then call the "toDateTimeString()" method with the format of the date.
{{ now()->format('Y-m-d') }}

Getting Current Time in Laravel


To get the current time you can provide a different format to the "toDateTimeString()" method and it's as follows.
{{ now()->format('H:i:s') }}

Getting Current Day in Laravel


Lastly to get the "day" you can provide the format "l" inside "toDateTimeString()" method. (lowercase "L")
{{ now()->format('l') }}

Other Reads

If you like our tutorial, do make sure to support us by being our Patreon or buy us some coffee ☕️

)