Date in the format dd / mm / yyyy?

4

I created a table, where I put the user's registration on a card for printing; so this table has several records (5 per page) and for each page I access a record in the same table I made an array_push with values ->

$sql = mysql_query("SELECT * FROM cartao LIMIT $inicial, $numreg ");
$sql_conta = mysql_query("SELECT * FROM cartao ");
$quantreg = mysql_num_rows($sql_conta); 

$Nascimento = array();
$Batismo = array();
$Comunhao = array();
$Emissao = array();

while($linha = mysql_fetch_array($sql_conta, MYSQL_ASSOC)){;
  array_push($Nascimento, $linha['Nascimento']);
  array_push($Batismo, $linha['Batismo']);
  array_push($Comunhao, $linha['Comunhao']);
  array_push($Emissao, $linha['Emissao']);

}if ($_GET['pag'] > 0 ){  
$pegaid = (int) $_GET['pag'];
$id = "$pegaid";
$soma = $id * 5 ;
}

Inside the Table I pull the log data that comes out in format ('yyyy / mm / dd') the table works like this:

td height="42"><a>Nascimento:</a>
                   <?php
                  echo '<b>'; 
                 if ($_GET['pag'] > 0 ){
                     print $Nascimento[0 + $soma]; 
                 }else{
                     print $Nascimento[0];
                     }
                 echo '</b>';    
                     ?>
                  </td>

I wanted to KNOW how to invert the format without giving a problem in the rest of the code the other records I took to find it of no importance.  OBS :. All records there are dates; The registration record is an automatic registration !!! Someone help me.

    
asked by anonymous 19.08.2014 / 23:51

3 answers

4

Optimizing your query counter:

Your query does not count, it returns ALL records !!!
SELECT * FROM cartao
The correct would be:
SELECT COUNT(*) AS count FROM cartao LIMIT $inicial, $numreg Home My suggestion to tell the records is below:

2nd QUERY: SELECT SQL_CALC_FOUND_ROWS * FROM cartao LIMIT $inicial, $numreg
br> SELECT FOUND_ROWS() will return total records

1) using class FOUND_ROWS

$date = new DateTime( '2014-08-19' );
echo $date-> format( 'd-m-Y' );

date( 'd-m-Y' , strtotime( '2014-08-19' ) );

> output : 08-19-2014

    
19.08.2014 / 23:59
2

In the SQL itself you use date_format just like the example below:

$sql = mysql_query("SELECT date_format(Nascimento,'%d/%m/%Y') Nascimento, Batismo, Comunhao, Emissao FROM cartao LIMIT $inicial, $numreg ");
$sql_conta = mysql_query("SELECT * FROM cartao ");
$quantreg = mysql_num_rows($sql_conta); 

$Nascimento = array();
$Batismo = array();
$Comunhao = array();
$Emissao = array();

while($linha = mysql_fetch_array($sql_conta, MYSQL_ASSOC)){;
     array_push($Nascimento, $linha['Nascimento']);
     array_push($Batismo, $linha['Batismo']);
     array_push($Comunhao, $linha['Comunhao']);
     array_push($Emissao, $linha['Emissao']);

}
if ($_GET['pag'] > 0 ){  
    $pegaid = (int) $_GET['pag'];
    $id = "$pegaid";
    $soma = $id * 5 ;
}
    
20.08.2014 / 00:02
2

Using a simple explode and implode :

$date = '2014-08-19';
echo implode('/',array_reverse(explode('-',$date)));
    
20.08.2014 / 05:43