如何在laravel 5.4中获取created_at日期

时间:2017-05-09 13:52:18

标签: php sql laravel-5

我尝试仅获取用户的created_at 日期,但同时也提取时间。代码:

{{{ isset(Auth::user()->created_at) ? Auth::user()->created_at : Auth::user()->email }}}

结果:2017-05-09 11:44:09

2 个答案:

答案 0 :(得分:9)

您可以使用toDateString()

{{ isset(Auth::user()->created_at) ? Auth::user()->created_at->toDateString() : Auth::user()->email }}

format()

{{ isset(Auth::user()->created_at) ? Auth::user()->created_at->format('m/d/Y') : Auth::user()->email }}

答案 1 :(得分:3)

我还有其他解决方案:

where('created_at', '>=', date('Y-m-d').' 00:00:00'));
whereDate('created_at', '=', date('Y-m-d'));
whereDate('created_at', '=', Carbon::today()->toDateString());

它将100%工作