LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   doctrine - how to use cast() in DQL? (https://www.linuxquestions.org/questions/programming-9/doctrine-how-to-use-cast-in-dql-943931/)

eantoranz 05-08-2012 02:23 PM

doctrine - how to use cast() in DQL?
 
Hi!

I just hit a brick wall when using a cast function in dql:

Code:

PHP Fatal error:  Uncaught exception 'Doctrine\ORM\Query\QueryException' with message '[Syntax Error] line 0, col 125: Error: Expected known function, got 'date'' in /home/antoranz/Descargas/php/DoctrineORM-2.2.1/Doctrine/ORM/Query/QueryException.php:42
So.... what kind of voodoo will I have to use on doctrine to use a cast in DQL?

Just in case, what I need is get entities of which a datetime field matches today (in other words, match only the date).

I'm using something like this:
Code:

$em->createQuery("select u from Entity u where cast(u.datetimefield as date)=CURRENT_DATE");
Is there some other hack to implement it?

Snark1994 05-10-2012 10:43 AM

Do you need the CAST() bit? In SQL, I would just make sure CURRENT_DATE is a string in the same format as the datetimefield, and then used a normal "WHERE x=y" clause. Is it different for DQL?


All times are GMT -5. The time now is 07:46 AM.