transform Y-m-d H-i-s into d-m-Y H-i-s

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 performing this operation with the date command, but it did not work.

    
asked by anonymous 24.04.2018 / 21:50

2 answers

0

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

    
25.04.2018 / 01:58
4

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

    
24.04.2018 / 22:28