Reputation: 31
I try to do a database query using
$position = $repository->findBy(
array('id' => $profileId,'datum' => '10.07.2011'),
array('timestamp', 'DESC')
);
the database looks like
id haveInCircles inOtherCircles datum timestamp
1 24 14 11.07.2011 1310403840
1 20 10 10.07.2011 1310317440
1 10 5 09.07.2011 1310317440
1 25 17 12.07.2011 1310468838
The result I get is always the data of the last day into the database. In this case '12.07.2011'.
Upvotes: 3
Views: 1212
Reputation: 2184
Using varchar for dates is probably the worst approach possible. Change the datum field to date or datetime, change your models accordingly so the doctine field is date and then do something like:
$position = $repository->findBy(
array('id' => $profileId,'datum' => new Datetime('2011-07-10')),
array('timestamp' => 'DESC')
);
http://www.php.net/manual/en/datetime.construct.php
Brief on schema practises which i would advice to review: http://brixican.blogspot.ca/2011/04/5-mysql-best-practices-when-designing.html
Upvotes: 4
Reputation: 108
I agree with others that you should change the field to Datetime format, however if you are using Symfony2 in the developer mode you can check SQL logs (DB Queries) that correspond to your Doctrine ORM query builder and from there you may know what's wrong with your query builder
Upvotes: 0
Reputation: 101
If database field for 'datum' is datetime, try to use: 2011-07-10 format :-)
Symfony2 articles
Upvotes: 1