Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Symfony2 Doctrine

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'.

like image 555
Daniel Avatar asked Jun 28 '26 12:06

Daniel


1 Answers

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

like image 145
Feras Avatar answered Jul 01 '26 02:07

Feras



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!