LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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.

Notices

Reply
 
Search this Thread
Old 05-08-2012, 03:23 PM   #1
eantoranz
Senior Member
 
Registered: Apr 2003
Location: Colombia
Distribution: Kubuntu, Debian, Knoppix
Posts: 1,982
Blog Entries: 1

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

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

Rep: Reputation: 345Reputation: 345Reputation: 345Reputation: 345
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 11:45 AM.
 
  


Reply

Tags
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 03:59 PM
[SOLVED] doctrine / postgres - timestamp without timezone eantoranz Programming 2 05-07-2012 05:43 PM
how to cast in C++? knobby67 Programming 3 02-07-2008 12:54 PM
LXer: Google, the Associated Press, and the Fair Use Doctrine LXer Syndicated Linux News 0 09-20-2006 05:21 PM
what does a cast in c++ actually do? markhod Programming 2 12-23-2004 10:01 AM


All times are GMT -5. The time now is 09:33 AM.

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