jpql date comparison today

Manuel picture Manuel · Nov 27, 2012 · Viewed 53.8k times · Source

I need a jpql query to find all the LoadFileHistory which finishDate be greater than the currente date (since 00:00:00). For instance greater than 27/11/2012 00:00:00.

I already have this one "select o from LoadFileHistory o where o.finishDate = CURRENT_DATE" but gets me nothing.

Answer

ppeterka picture ppeterka · Nov 27, 2012

You should get today's date to the query like detailed here (java.util.Date has the hour, minute, second too...)

The you should supply it to your query:

Query q = em.createQuery("select o from LoadFileHistory o where o.finishDate > :today ");
q.setParameter("today",todaysDateObject,TemporalType.DATE);
q.getResultList();