更改日期格式不起作用

时间:2014-05-14 23:23:03

标签: php

我想将日期格式从(ymd)更改为(dmy),但我有一个错误:警告:date_format()期望参数1为DateTime,字符串在D:\中给出第124行的wamp \ www \ pharmacie \ vente \ index.php 调用堆栈

if(isset($_POST['date_vente'])) {
$VenteObject = $managerVente->getListParDate(date_format($_POST['date_vente'], 'd-m-y')) ; 
echo $_POST['date_vente'] ; 
}
else {
$VenteObject = $managerVente->getList() ;
}

这是请求

  public function getListParDate($date)
  {
    $vente = array();
    $q = $this->_db->prepare('SELECT * FROM vente where date="'.$date.'" ORDER BY id DESC ') or die(print_r($req->errorInfo()));
    $q->execute() ;

       while ($donnees = $q->fetch(PDO::FETCH_ASSOC))
    {
        $vente[] = new Vente($donnees);
    }
        return $vente;

  }

echo $ _POST [' date_vente']; 给出y-m-d

1 个答案:

答案 0 :(得分:1)

documentation向您展示了如何使用DateTime类:

$date = new DateTime($_POST['date_venue']);
$new_date = $date->format('d-m-y');

$VenteObject = $managerVente->getListParDate($new_date) ; 
echo $new_date;