Home / Snippets / How to get current Date, Time and Day in Laravel 8
How to get current Date, Time and Day in Laravel 8 cover

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

14K

2 years ago

0 comments

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

notion avatar

Alaz

Week-end developer currently experimenting with web, mobile, and all things programming.

Topics:

Frontend

Resource

Average

Average

Support Us

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

Welcome to PostSrc V3

PostSrc Dark Logo

You have to login to favorite this