0 votes
812 views
in Laravel by

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

I tried to echo $ldate = new DateTime('today'); and $ldate = new DateTime('now');

But it is returning 1 always.

How can I get the current date, time , day in laravel.

1 Answer

0 votes
by

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.

Related questions

0 votes
1 answer 929 views
0 votes
1 answer 1.0k views
0 votes
1 answer 1.6k views
0 votes
0 answers 985 views
asked Feb 13, 2017 in Laravel by Simply
+1 vote
1 answer 1.7k views
asked Dec 7, 2016 in Laravel by Pinto
0 votes
0 answers 970 views
asked Dec 6, 2016 in Laravel by Jinu
...