Reputation: 760
I have a column named birth_date
in MySQL database with a type of date
.
Now, I would like to show it in my view in this format : May 23, 2008
I tried:
{{ $user->user_information->birth_date->format('m-d-Y') }}
it showed:
ErrorException (E_ERROR) Call to a member function format() on string
I also tried
{{ date('m-d-Y', $user->user_information->baptism_date) }}
it showed:
ErrorException (E_ERROR) A non well formed numeric value encountered
Can anyone assist me with the right formatting code?
Upvotes: 0
Views: 121
Reputation: 26258
You can use the date()
function for this purpose like:
date('m-d-Y', strtotime($user->user_information->birth_date));
or you can also use Carbon
for this purpose like:
{{ \Carbon\Carbon::parse($user->user_information->birth_date)->format('m-d-Y')}}
For May 23, 2008:
date('M d, Y', strtotime($user->user_information->birth_date));
Working code snippet
date()
format list is available here
M
- A short textual representation of a month, three letters
Upvotes: 1
Reputation: 775
you can use date function. try this code:
{{ date('F j, Y', strtotime($user->user_information->birth_date)); }}
Upvotes: 1
Reputation: 2292
Try this code.
{{ Carbon\Carbon::parse($user->user_information->birth_date)->format('F d, Y') }}
Upvotes: 1