Data format php pdo [duplicate]

1

Input:

<html>  
 <form action="../controller/progPrecontrole.php" method="POST" onsubmit="return valid();">
   <input type="hidden" name="id" value="<?php echo $id; ?>"/>
   <p>Data Saída:</p>
   <input type="text" maxlength="10" onkeypress="return dateMask(this, event);" id="saida" name="saida" value="<?php echo $DtSaida; ?>"/>
   <input type="submit" class="button" value="Aplicar"/>
   <a class="secondary button" href="programacao.php"> Voltar </a>
 </form>
</html>

Functions:

<?php
class ProgDAO{

private $conn;

public function __construct($connection) {
    $this->conn = $connection;
}

public function listar($id){
        $prog = new Prog();
        $stmt = $this->conn->prepare(
            'SELECT * FROM GTCLogist WHERE ID = :ID'
        );
        $stmt->bindValue(':ID', $id, PDO::PARAM_INT);
        $stmt->execute();
        if($stmt) {
            while($row = $stmt->fetch(PDO::FETCH_OBJ)) {
                $prog->setid($row->ID);
                $prog->setsaida(date('d/m/Y', strtotime($row->DtSaida)));
            }
        }
    return $prog;
}

public function editar(Prog $prog){
    $this->conn->beginTransaction();
    try {
        $stmt = $this->conn->prepare(
            'UPDATE GTCLogist SET DsMotorista = :DsMotorista, 
                DtSaida = :DtSaida WHERE ID = :ID'
        );
        $stmt->bindValue(':ID', $prog->getid(), PDO::PARAM_INT);
        $stmt->bindValue(':DtSaida', $prog->getsaida(), PDO::PARAM_INT);
        $stmt->execute();
        $this->conn->commit();
    }
    catch(Exception $e) {
        $this->conn->rollback();
    }
}
?>
The problem is that when I edit this input it does not save, the bank format is US standard date (yyyy, mm, dd), I used the function list to print inside the input dd / mm / yyyy because when editing it saves mm / dd / yyyy, if you put a value greater than 12 in the first field of the date it already ignores thinking it is a month. I need it saved in the format dd / mm / yyyy.

    
asked by anonymous 18.01.2016 / 20:15

1 answer

1

Right code as it was:

$data_formatada = DateTime::createFromFormat('d/m/Y', $DtSaida);

Input:

<input type="date" maxlength="10" onkeypress="return dateMask(this, event);" id="saida" name="saida" value="<?php echo $data_formatada->format('Y-m-d'); ?>"/>
    
19.01.2016 / 13:35