symfony doctrine类型datetime预期格式y-m-d h:i:s。

时间:2022-10-22 18:46:03

I have a problem in symfony when I try to select some items from database with doctrine.

当我试图从数据库中选择一些条目时,我遇到了一个问题。

I run this:

我运行这个:

$allOrders = $em->getRepository('MyBundle:Dieta')->findBy(array('diet_status'=>'active'));
var_dump($allOrders);

And I get the following error:

我得到了以下错误:

Could not convert database value "2014-03-03" to Doctrine Type datetime. Expected format: Y-m-d H:i:s

不能将数据库值“2014-03-03”转换为Doctrine类型datetime。预期的格式:Y-m-d H:我:s

When I insert the date in the database i do it like this:

当我在数据库中插入日期时,我这样做:

$format = 'd/m/Y';
$date = \DateTime::createFromFormat($format, $_POST['dietStartDate']);
$dietStartDate = $date->format('Y-m-d H:i:s');
$dietStartDate = new \Datetime($dietStartDate);

$timestamp = strtotime(str_replace('/', '-', $_POST['dietStartDate']));
$timestamp7 = strtotime('+7 days', $timestamp);
$datetime = date("Y-m-d H:i:s", $timestamp7);
$dietDateEnd = new \Datetime($datetime);

The $dietStartDate and $dietDateEnd are inserted in a datetime column in database. In the doctrine.yml I have it also declared as datetime.

$dietStartDate和$dietDateEnd插入数据库中的datetime列。在教义。我还把它声明为datetime。

Any ideas ?

什么好主意吗?

1 个解决方案

#1


7  

From the value "2014-03-03", it seems that your database column type is date but not datetime.

从“2014-03-03”的值来看,您的数据库列类型似乎是日期,而不是datetime。

Run php app/console doctrine:schema:update to check whether there are changes.

运行php应用程序/控制台原则:模式:更新检查是否有更改。

#1


7  

From the value "2014-03-03", it seems that your database column type is date but not datetime.

从“2014-03-03”的值来看,您的数据库列类型似乎是日期,而不是datetime。

Run php app/console doctrine:schema:update to check whether there are changes.

运行php应用程序/控制台原则:模式:更新检查是否有更改。