AngularAngularAngular AngularAngularAngular - 1 year ago 138
PHP Question

Getting Current date, time , day in laravel

I need to get the current date, time, day using laravel

I tried to echo

$ldate = new DateTime('today');
$ldate = new DateTime('now');

But it is returning 1 always.

How can i get the current date, time , day in larvel

Answer Source

Laravel has the Carbon dependency attached to it.

Carbon::now(), include the Carbon\Carbon namespace if necessary.

Edit (usage and docs)

Say I want to retrieve the date and time and output it as a string.

$mytime = Carbon\Carbon::now();
echo $mytime->toDateTimeString();

This will output in the usual format of Y-m-d H:i:s, there are many pre-created formats and you will unlikely need to mess with PHP date time strings again with Carbon.


String formats for Carbon:

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download