Visit Jeremy's Blog.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 05-08-2012, 02:23 PM   #1
Senior Member
Registered: Apr 2003
Location: Costa Rica
Distribution: Kubuntu, Debian, Knoppix
Posts: 2,064
Blog Entries: 1

Rep: Reputation: 90
doctrine - how to use cast() in DQL?


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

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

Last edited by eantoranz; 05-08-2012 at 02:25 PM.
Old 05-10-2012, 10:43 AM   #2
Senior Member
Registered: Sep 2010
Location: Wales, UK
Distribution: Arch
Posts: 1,632
Blog Entries: 3

Rep: Reputation: 346Reputation: 346Reputation: 346Reputation: 346
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?

Last edited by Snark1994; 05-10-2012 at 10:45 AM.


cast, current_date, date, doctrine, dql

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
doctrine / PHP - how to handle a table that has no PK? eantoranz Programming 3 05-08-2012 02:59 PM
[SOLVED] doctrine / postgres - timestamp without timezone eantoranz Programming 2 05-07-2012 04:43 PM
how to cast in C++? knobby67 Programming 3 02-07-2008 11:54 AM
LXer: Google, the Associated Press, and the Fair Use Doctrine LXer Syndicated Linux News 0 09-20-2006 04:21 PM
what does a cast in c++ actually do? markhod Programming 2 12-23-2004 09:01 AM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:00 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration