Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get created_at date only not time in laravel 5.4

Tags:

sql

php

laravel-5

I'm trying to get the created_at date of a user only but it is also fetching the time. Code:

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

Results: 2017-05-09 11:44:09

like image 657
Abbas Ahmad Avatar asked May 09 '17 13:05

Abbas Ahmad


People also ask

How can I get Created date in laravel?

You can get date from created_at filed in laravel using toDateString() and format() method on created_at attribute.

How can get today date in laravel?

From Laravel 5.5 you can use now() function to get the current date and time. In blade file, you can write like this to print date.

How do I change a date format to a string in laravel?

Change date format by accessor method in model in Laravel 8Create accessor methods getCreatedAtAttribute() and getUpdatedAtAttribute() for created_at and updated_at column in model. These accessors will automatically be called by Eloquent when we retrieve the value of the created_at and updated_at attributes.


1 Answers

You can use toDateString()

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

or format()

{{ isset(Auth::user()->created_at) ? Auth::user()->created_at->format('m/d/Y') : Auth::user()->email }}
like image 116
peterm Avatar answered Nov 15 '22 18:11

peterm