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
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.
Any ideas ?
From the value "2014-03-03"
, it seems that your database column type is date
but not datetime
.
Run php app/console doctrine:schema:update
to check whether there are changes.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With