Jump to content
Fórum Script Brasil
  • 0

Converter Datas



Script postado por: Fabyo

Converter Datas

Função para conveter datas

Se ela estiver assim 0000-00-00, ela converte para 00/00/0000.

Se ela estiver assim 00/00/0000, ela converte para 0000-00-00.

function converte_data($data){
    if (strstr($data, "/")){//verifica se tem a barra /
  $d = explode ("/", $data);//tira a barra
  $invert_data = "$d[2]-$d[1]-$d[0]";//separa as datas $d[2] = ano $d[1] = mês etc...
  return $invert_data;
    elseif(strstr($data, "-")){
  $d = explode ("-", $data);
  $invert_data = "$d[2]/$d[1]/$d[0]";    
  return $invert_data;
  return "Data invalida";
outro jeito mais simples:
$data = "0000-00-00";
$arr = explode("-", $data); 
$nova_data = "$arr[2]/$arr[1]/$arr[0]"; //00/00/0000
mais simples ainda:
$snova_data = implode("-", array_reverse(explode("/", $data)));

Link to comment
Share on other sites

0 answers to this question

Recommended Posts

There have been no answers to this question yet

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Forum Statistics

    • Total Topics
    • Total Posts
  • Create New...