persistence@glassfish.java.net

Re: how to compare 2 dates in a JPA QL query

From: Quintin Beukes <quintin_at_last.za.net>
Date: Wed, 13 Aug 2008 11:57:04 +0200

The only JPA QL functions for dates are the
CURRENT_TIMESTAMP/TIME/DATE "constants".
To compare dates you just do: ==, >=, <=, <, etc...

I assume you have a date+time/timestamp field, and you want to see if
their dates match, no matter what time of day they are for? To do
this, I'm not sure. I guess you'll have to do a between or something,
or create a native query (which isn't ideal).

So I can't answer your question, sorry. Just figured I'd let you know
about the limitation in date functions. I'm basing this on the BEA JPA
reference: http://edocs.bea.com/kodo/docs41/full/html/ejb3_langref.html

Quintin

On Wed, Aug 13, 2008 at 11:30 AM, chflb <labidi.chifa_at_gmail.com> wrote:
>
> hello all,
>
> how can i compare 2 dates in JPA QL ,?
>
> my idea was to convert the dates to String, and i used 'to_char',
> but i think it doesn't work in JPA QL;
> this is my query(it works in oracle but not in java) :
>
> Query q=em.createQuery("select sum(o.montant) from Operation o join
> o.codTransac t join o.codCaisse c where (t.sens='D')and
> (to_char(c.dateCaisse,'MM/DD/YYYY')=to_char(o.dateOp,'MM/DD/YYYY'))");
>
> can some one help me?
> thanks
>
>
> --
> View this message in context: http://www.nabble.com/how-to-compare-2-dates-in-a-JPA-QL-query-tp18959789p18959789.html
> Sent from the java.net - glassfish persistence mailing list archive at Nabble.com.
>
>



-- 
Quintin Beukes