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

12K

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

Ahmad Aziz

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 ☕️

Post Tutorials

Learn trending tutorials for ReactJs, React Native, VueJS, NextJs, Laravel, Tailwind CSS, and Flutter development.
View Tutorials

Code Components

Collection of Tailwind CSS components for everyone to use. Browse all of the components that's right for your web projects
View Components

Welcome to PostSrc V3

PostSrc Dark Logo

You have to login to favorite this