Getting Current date, time , day in laravel
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.
Documentation: https://github.com/briannesbitt/Carbon
String formats for Carbon: http://carbon.nesbot.com/docs/#api-formatting
Try this,
$ldate = date('Y-m-d H:i:s');
Php has a date function which works very well. With laravel and blade you can use this without ugly <?php
echo tags. For example, I use the following in a .blade.php
file...
Copyright © {{ date('Y') }}
... and Laravel/blade translates that to the current year. If you want date time and day, you'll use something like this:
{{ date('Y-m-d H:i:s') }}