Ir para conteúdo

POWERED BY:

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

Gão

Fatal error: Call to undefined function date_create_from_format()

Recommended Posts

Boa tarde estou tentando executar um script que é busca por datas e ele me aparece este erro

 

Fatal error: Call to undefined function date_create_from_format()

 

Segue o script:

<!DOCTYPE html>
<!--[if lt IE 7 ]> <html lang="en" class="no-js ie6 lt8"> <![endif]-->
<!--[if IE 7 ]>    <html lang="en" class="no-js ie7 lt8"> <![endif]-->
<!--[if IE 8 ]>    <html lang="en" class="no-js ie8 lt8"> <![endif]-->
<!--[if IE 9 ]>    <html lang="en" class="no-js ie9"> <![endif]-->
<!--[if (gt IE 9)|!(IE)]><!--> <html lang="en" class="no-js"> <!--<![endif]-->
    <head>
        <meta charset="UTF-8" />
        <!-- <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">  -->
        <title>CADASTRAR DEPARTAMENTO</title>
        <meta name="viewport" content="width=device-width, initial-scale=1.0"> 
        <meta name="description" content="Login and Registration Form with HTML5 and CSS3" />
        <meta name="keywords" content="html5, css3, form, switch, animation, :target, pseudo-class" />
        <meta name="author" content="Codrops" />

<script type="text/javascript">
   function DoPrinting(){
      if (!window.print){
         alert("Use o Netscape  ou Internet Explorer \n nas versões 4.0 ou superior!")
         return
      }
      window.print()
   }

</script>
<style rel="stylesheet" type="text/css" media="print">
   #botao{display:none}
</style>
<?PHP
//include "sessao.php";
include "conecta.php";
?>
<?php
// inclui arquivo de conexão com o banco
    if (empty($_POST['busca1'])) 
    {
        echo "Digite uma palavra-chave para sua busca";
echo "<script>window.location='buscaloc2.php';alert(''Coloque as Duas Datas-Lembrando qua primeira deve ser menor que a segunda');</script>";
    }
    else // define valores se o resultado não for vazio
    {


 $dataInicio = $_POST['busca'];
$date = date_create_from_format('d/m/Y', $dataInicio);
$dataInicio = date_format($date, 'Y-m-d');


$dataFim =$_POST['busca1'];
$date = date_create_from_format('d/m/Y', $dataFim);
$dataFim = date_format($date, 'Y-m-d');

 // query de consulta
  $sql = "SELECT *FROM roteiro WHERE data_rot AND data_rot BETWEEN '$dataInicio' AND '$dataFim'  order by idrot ASC ";
            


  
       // echo "Você tem um total de ".$total." Roteiros Nesta Data ".$dataInicio = $_POST['busca']."<br><br>";

       
        // gera o loop com os resultados
        while($linha = mysql_fetch_array($sql))
        {
           // echo "O ID que você procura é: ".$linha['pc_fil']."<br>";
          //  echo '<a href="pegasp.php?id='.$linha['id_fil'].'">'.$linha['pc_fil'].'</a><br>'."\n";
            
           $idfil=$linha['idrot'];
$fil2=$linha['cli_rot'];
$fil3=$linha['raz_rot'];
$fil4=$linha['cnpj_rot'];
$fil5=$linha ['end_rot'];
$fil6=$linha['cont_rot'];
$fil7=$linha['tel_rot'];
$fil8=$linha['col_rot'];
$fil9=$linha['sol_rot'];
$fil10=$linha ['serv_rot'];
$fil11=$linha['data_rot'];
$fil12=$linha['obs_rot'];
$fil13=$linha['prot_rot'];
$partes_da_data = explode('-',$fil11); 
     $data_brasileiro = $partes_da_data[2].'/'.$partes_da_data[1].'/'.$partes_da_data[0];
$partes_da_data1 = explode('-',$fil11); 
     $data_brasileiro1 = $partes_da_data1[2].'/'.$partes_da_data1[1].'/'.$partes_da_data1[0];




$data1 = date("d/m/Y"); 







?>
   
         

     
    <table width="200" border="0" >
  <tr>
    <td><table width="652" border="0" align="center">
      <tr>
          <td><label for="username13" class="uname"  >CNPJ/CPF:</label></td>
          <td><b><?php echo ($fil4)?></b></td>
        </tr>
        <tr>
          <td><label for="username15" class="uname"  >Cliente:</label></td>
          <td><b><?php echo ($fil2)?></b></td>
        </tr>
        <tr>
          <td><label for="username16" class="uname"  >Razão Social:</label></td>
          <td><b><?php echo ($fil3)?></b></td>
        </tr>
        <tr>
          <td><label for="username14" class="uname"  >Endereço:</label></td>
          <td><b><?php echo ($fil5)?></b></td>
        </tr>
        <tr>
          <td><label for="username17" class="uname"  >Contato:</label></td>
          <td><b><?php echo ($fil6)?></b></td>
        </tr>
        <tr>
          <td width="160"><label for="username2" class="uname"  >Telefone:</label></td>
          <td width="482"><b><?php echo ($fil7)?></b></td>
        </tr>
        <tr>
          <td><label for="username18" class="uname"  >Colaborador:</label></td>
          <td><b><?php echo ($fil8)?></b></td>
        </tr>
        <tr>
          <td><label for="username6" class="uname"  >Solicitante:</label></td>
          <td><b><?php echo ($fil9)?></b></td>
        </tr>
        <tr>
          <td><label for="username3" class="uname" > Data de Solicitação:</label></td>
          <td><b><?php echo ($data_brasileiro)?></b></td>
        </tr>
        <tr>
          <td colspan="2"><label for="username4" class="uname"  >Existe Protocolo?:<b><?php echo ($fil13)?></b></label></td>
        </tr>
      </table>
                          <table width="652" border="0">
                            <tr>
                              <td><label for="username4" class="uname"  >Observação:<b><?php echo ($fil12)?></b></label></td>
                            </tr>
                    </table>
                    <table width="652" border="0">
                            <tr>
                              <td><label for="username5" class="uname"  ><center>Serviço a ser executado</center></label></td>
                            </tr>
                            
      </table>
                          <p><b><?php echo ($fil10)?></b></p>
      <p> </p>
<p>------------------------------------------------------------------------------------------------------------</p>
<table width="655" border="0">
  
</table>
<p> </p>
<p> </p>
<table width="656" border="0">
        
      </table></td>
  </tr>
</table><br><br>
    <?PHP

}}

?>
<input type="button" value="imprimir" onClick="DoPrinting()" id="botao" />
    <div id="paginador" align="center">
  

</div>

 

OBRIGADO

Compartilhar este post


Link para o post
Compartilhar em outros sites

Qual a sua versão do PHP, esta função está disponível a partir da versão 5.3.

 

http://php.net/date_create_from_format

 

Acredito que a sua versão seja a 5.2, você pode verificar com a seguinte função:

echo phpversion();

Compartilhar este post


Link para o post
Compartilhar em outros sites

Entao o problema é que no servidor meu da dando erro....no wamp não esta só quando eu passo pro meu servidor do site

Compartilhar este post


Link para o post
Compartilhar em outros sites

No caso quem procurar pela data vai digitar 02/01/2015? ou tem que digitar 2015-01-02...

 

Porque digitando o primeiro exemplo 02/01/2015 ele não aparece nada....e digitando o segundo ele aparece isso

 

( ! ) Notice: Undefined offset: 2 in C:\teste\wamp\www\roteiro\buscaloc.php on line 46 Call Stack # Time Memory Function Location 1 0.0005 393552 {main}( ) ..\buscaloc.php:0
( ! ) Notice: Undefined offset: 1 in C:\teste\wamp\www\roteiro\buscaloc.php on line 46 Call Stack # Time Memory Function Location 1 0.0005 393552 {main}( ) ..\buscaloc.php:0
( ! ) Fatal error: Uncaught exception 'Exception' with message 'DateTime::__construct() [datetime.--construct]: Failed to parse time string (yyyy-mm-dd) at position 0 (y): The timezone could not be found in the database' in C:\teste\wamp\www\roteiro\buscaloc.php on line 46 ( ! ) Exception: DateTime::__construct() [datetime.--construct]: Failed to parse time string (yyyy-mm-dd) at position 0 (y): The timezone could not be found in the database in C:\teste\wamp\www\roteiro\buscaloc.php on line 46 Call Stack # Time Memory Function Location 1 0.0005 393552 {main}( ) ..\buscaloc.php:0 2 0.0271 400792 DateTime->__construct( ) ..\buscaloc.php:46

Compartilhar este post


Link para o post
Compartilhar em outros sites

Desculpe a Ignorancia , mas ficaria assim??

 

$dataInicio = $_POST['busca'];
$aux = explode('/', $dataInicio);
$date = new DateTime(sprintf('%04d-%02d-%02d', $aux[2], $aux[1], $aux[0]));
var_dump($dataInicio, $aux, $date);
Obrigado

Compartilhar este post


Link para o post
Compartilhar em outros sites

apareceu isso

 

string '02/01/2015' (length=10)
array
0 => string '02' (length=2)
1 => string '01' (length=2)
2 => string '2015' (length=4)
object(DateTime)[1]
public 'date' => string '2015-01-02 00:00:00' (length=19)
public 'timezone_type' => int 3
public 'timezone' => string 'UTC' (length=3)
string '02/01/2015' (length=10)
array
0 => string '02' (length=2)
1 => string '01' (length=2)
2 => string '2015' (length=4)
object(DateTime)[2]
public 'date' => string '2015-01-02 00:00:00' (length=19)
public 'timezone_type' => int 3
public 'timezone' => string 'UTC' (length=3)


Somente colocando assim:

 

2015-01-02 ai ele busca.....mas ao contrario aparece sem registro


Cara arrumei um script que funcionou aqui beleza..segue ai pra quem precisar

 

 

$dataInicio = $_POST['busca'];
$partes_da_data = explode('/',$dataInicio);
$data_brasileiro = $partes_da_data[2].'/'.$partes_da_data[1].'/'.$partes_da_data[0];
$data_brasileiro;

Compartilhar este post


Link para o post
Compartilhar em outros sites

×

Informação importante

Ao usar o fórum, você concorda com nossos Termos e condições.