How do I change a date that comes from the database as Y-m-d H-i-s (2018-04-24 16:07:17)
in d-m-Y H-i-s (24-04-2018 16:07:17)
in php?
I tried performing this operation with the date command, but it did not work.
How do I change a date that comes from the database as Y-m-d H-i-s (2018-04-24 16:07:17)
in d-m-Y H-i-s (24-04-2018 16:07:17)
in php?
I tried performing this operation with the date command, but it did not work.
Use date
in conjunction with function strtotime()
, thus date('d-m-Y H:i:s', strtotime($dataVindaDoBanco));
You can use the DateTime
class of PHP
, see;
$date = new DateTime("2018-04-24 16:07:17");
print_r($date->format("d-m-Y H:i:s")); // saída: 24-04-2018 16:07:17
You can use it dynamically if you prefer;
$date = (new DateTime("2018-04-24 16:07:17"))->format("d-m-Y H:i:s")
See more about the class DateTime na documentação do PHP