Valida_Data($arr[1], $arr[0], $ano); $this->Valida_Hora("$hora:$arr2[1]:$arr2[2]"); if($redux == 0) { return "$ano-$arr[1]-$arr[0] $hora:$arr2[1]:$arr2[2]"; } else { return "$ano-$arr[1]-$arr[0]"; } } else { $arr = explode ("/", $data); $data = "$arr[2]-$arr[1]-$arr[0]"; $this->Valida_Data($arr[1], $arr[0], $arr[2]); return $data; } } elseif(strstr($data, "-")) { if (preg_match("/( \d{2}(:\d{2}){2})$/", $data)) { $arr = explode ("-", $data); $arr2 = explode(":" , $data); $dia = substr($arr[2] , 0, 2); $hora = substr($arr[2] , 3, 2); $ano = substr($arr2[0], 0,4); $this->Valida_Data($arr[1], $dia, $arr[0]); $this->Valida_Hora("$hora:$arr2[1]:$arr2[2]"); if($redux == 0) { return "$dia/$arr[1]/$arr[0] $hora:$arr2[1]:$arr2[2]"; } else { return "$dia/$arr[1]/$arr[0]"; } } else { $arr = explode ("-", $data); $data = "$arr[2]/$arr[1]/$arr[0]"; $this->Valida_Data($arr[1], $arr[2], $arr[0]); return $data; } } } function Valida_Data($dia, $mes, $ano) { if( !checkdate($dia, $mes, $ano)) { echo "Data Invalida"; exit; } } function Valida_Hora($hora) { if( !preg_match("/^[012][0-9]:[0-5][0-9]:[0-5][0-9]$/i", $hora)) { echo "Hora Invalida"; exit; } elseif( preg_match("/^(24|25|26|27|28|29):.*$/i", $hora)) { echo "Hora Invalida"; exit; } } } $data = new data(); echo "18/05/1977 23:59:12 = ".$data->Converte_Data("18/05/1977 23:59:12")."
"; echo "18/05/1977 23:59:12 = ".$data->Converte_Data("18/05/1977 23:59:12", 1)."
"; echo "1977-05-18 22:45:12 = ".$data->Converte_Data("1977-05-18 22:45:12")."
"; echo "1977-05-18 22:45:12 = ".$data->Converte_Data("1977-05-18 22:45:12", 1 )."
"; echo "18/12/1977 = ".$data->Converte_Data("18/12/1977")."
"; echo "1977-12-18 = ".$data->Converte_Data("1977-12-18"); ?>