problem on the date 1970

0

I have a variable in my DB which stores the following value FECHA_MOV= "2015-03-19 04:34:20"

I would like to print (show) the date in this format "d-m-Y" ==> 19-03-2015 . But I get the next date "01-01-1970"

==========codigo============
$pdf->Cell(0,6,$g_chrHead,0,1);
    $originalDate = $rows["FECHA_MOV"];
    $date = new DateTime($originalDate);
    //echo $date->format('d-m-Y'); //esto si funciona
    //echo date("d-m-Y",strtotime($originalDate)); // aca sale 01-01-1970

            $pdf->SetFont('Courier','',8);

            while ($rows = sqlsrv_fetch_array($res_sql, SQLSRV_FETCH_ASSOC)){
                //echo date("d-m-Y",strtotime($rows["FECHA_MOV"]));
                $cad = str_repeat(" ",5) . substr(date("d-m-Y",strtotime($rows["FECHA_MOV"]))       . str_repeat(" ",12),0,14) ;                
                $cad .= substr($rows["NOM_MOV"]     . str_repeat(" ",25),0,27) ;
                $cad .= substr($rows["NOM_PAGO"]    . str_repeat(" ",25),0,27) ;
                $cad .= str_pad(number_format($rows["IMPORTE"],2,".",","), 12, " ", STR_PAD_LEFT) ;
                $cad .= str_repeat(" ",3) .substr($rows["NOMBRE"]   . str_repeat(" ",10),0,25) ;
                $pdf->Cell(0,6,$cad,0,1);
            }
        }

======================fin =============

How can I correct this error?

    
asked by Ronald Picón 10.09.2018 в 21:47
source

2 answers

0

I have effectively placed the following in the while:

while ($rows = sqlsrv_fetch_array($res_sql, SQLSRV_FETCH_ASSOC)){ 
echo strlen($rows["NOMBRE"]). "<br>"; 
echo $rows["NOMBRE"]; 

It gives me data, but when I do this:

while ($rows = sqlsrv_fetch_array($res_sql, SQLSRV_FETCH_ASSOC)){ 
echo strlen($rows["FECHA_MOV"]). "<br>"; 
echo $rows["FECHA_MOV"]; 

I get an error:

    
answered by 10.09.2018 в 23:47
0

The strtotime function converts from dates in English or in iso to timestamp php, $ originalDate is normally formatted according to the language configured in the SQLServer.

    
answered by 11.09.2018 в 17:37