JPQL Query Date Interval

I use JPA and JPQL. And I'm new to this world ;-) My query now gives me data between two dates.

Query query =em.createQuery("SELECT d FROM DTable d JOIN d.history p WHERE (d.vehicle.id = :vehicleId) AND (p.timestamp BETWEEN :curentDate AND :date)");

How can I tell JPQL to filter the data that it gives me Data between two dates, but with a time interval of 4 minutes?

Hope this is clear. Thanks for the suggestion.

+3
source share
1 answer

Your requirement: the difference between the two set dates must be at least four minutes. According to JPA 1.0 specification, a comparison expression between dates should follow this pattern

datetime_expression compare_operator datetime_expression

compare_operator =, > , > =, <, < =, < > . ,

Timestamp dateA ...
Timestamp dateB ...

Timestamp difference = new Timestamp(Math.abs(dateA.getTime() - dateB.getTime()));

Timestamp, 4

Timestamp fourMinutes = new Timestamp(0, 0, 0, 0, 4, 0, 0);

where :difference >= :fourMinutes
+1

All Articles