Reputation: 199
I am storing a CURRENT_TIMESTAMP
in a table as a 'Last Logged In Date/Time' section for my admin page.
When I echo out the value I want it to display in a nice format.
Here is what I have tried:
$last_logged_in = $rows['last_logged_in'];
echo $last_logged_in->format('M j Y g:i A');
I receive the following error:
Fatal error: Call to a member function format() on string
What am I doing wrong here. How can I make it display in a nice formatted way?
Please & Thank you.
Upvotes: 1
Views: 194
Reputation: 2075
MySQL stores dates as string, and format
is a DateTime method:
$last_logged_in = $rows['last_logged_in'];
$datetime_obj = new \DateTime($last_logged_in);
echo $datetime_obj->format('M j Y g:i A');
Upvotes: 1