Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jpql date comparison today

Tags:

java

jpa

jpql

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.

like image 936
Manuel Avatar asked Nov 27 '12 14:11

Manuel


2 Answers

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();
like image 53
ppeterka Avatar answered Sep 29 '22 08:09

ppeterka


In case you are looking for time level filtering with date. This 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 is of apache common.

like image 33
A_01 Avatar answered Sep 29 '22 08:09

A_01