Currently, this code : <?php echo $user->last_login?>
is showing this date format YYYY-MM-DD
from MySQL. How do i change it to this format DD-MM-YYYY
?
Thanks.
Edit : Problem solved. $date = new DateTime($user->last_login); echo $date->format('Y-m-d H:i:s');
Thanks guys!
You can do this:
date(d-m-Y", strtotime($user->last_login));
Or this:
$date = new DateTime($user->last_login);
echo $date->format('d-m-Y');
Or use Carbon (http://carbon.nesbot.com/docs/):
Carbon::createFromFormat('Y-m-d', $user->last_login)->format('d-m-Y');
Actually @frayne-konok was close. You'll need to do
echo date('d-m-Y', strtotime($user->last_login));
See the PHP docs for more date formatting codes: http://php.net/manual/en/function.date.php