Jpql comparison today

I need a jpql query to find the whole LoadFileHistory that ends the Date more than the current date (from 00:00:00). For example, more than 11/27/2012 00:00:00.

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

+6
source share
2 answers

Today you should get a date such as detailed here (java.util.Date has an hour, a minute, a second too ...)

You must specify it in your request:

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

If you are looking for time level filtering with a date. It worked for me.

 Date now = DateUtils.addMinutes(new Date(), -15); Query q = em.createQuery("Select u From Users u Where u.dateCreated > :today"); q.setParameter("today",now,TemporalType.TIMESTAMP); 

DateUtils has a generic Apache.

0
source

All Articles