fork download
  1. <?php
  2.  
  3. function inverteData($data){
  4. if(count(explode("/",$data)) > 1){
  5. return join("-",array_reverse(explode("/",$data)));
  6. }elseif(count(explode("-",$data)) > 1){
  7. return join("/",array_reverse(explode("-",$data)));
  8. }
  9. }
  10.  
  11. $data = "12/11/2018";
  12.  
  13. //para usar na query
  14. $dataInvertida = inverteData($data);
  15.  
  16. echo $dataInvertida;
  17.  
  18. echo PHP_EOL;
  19.  
  20. //alguma data retornada do select
  21. $dataBanco = "2018-11-21";
  22.  
  23. $dataBancoInvertida = inverteData($dataBanco);
  24.  
  25. //imprime na tela
  26.  
  27. echo $dataBancoInvertida;
Success #stdin #stdout 0s 82560KB
stdin
Standard input is empty
stdout
2018-11-12
21/11/2018