transformar Y-m-d H-i-s em d-m-Y H-i-s

Asked

Viewed 149 times

0

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 to perform this operation with the date command, but it didn’t work.

  • Use date together with the function strtotime(), thus date('d-m-Y H:i:s', strtotime($dataVindaDoBanco));

  • It worked man, thank you!

  • @Evandrolacerda could publish as a response his solution?

  • Published as a response!

2 answers

4

You can use the class DateTime 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 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

0


Use date together with the function strtotime(), thus date('d-m-Y H:i:s', strtotime($dataVindaDoBanco));

Browser other questions tagged

You are not signed in. Login or sign up in order to post.