[英]JPQL Query Date with interval
I am using JPA and JPQL. 我正在使用JPA和JPQL。 And I am new in this world;-) My Query is now giving me data between 2 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 he is giving me Data between 2 dates but with a time interval of 4 Minutes?. 我如何告诉JPQL过滤他在2个日期之间给我数据但是时间间隔为4分钟的数据?
I hope it is clear. 我希望很清楚。 Thanks for you suggestion.
谢谢你的建议。
Your requirement: the difference between two supplied dates should be at least four minutes. 您的要求:两个提供日期之间的差异应至少为四分钟。 According to JPA 1.0 specification, comparison expression between dates must follow this pattern
根据JPA 1.0规范,日期之间的比较表达必须遵循这种模式
datetime_expression comparison_operator datetime_expression
datetime_expression comparison_operator datetime_expression
Where comparison_operator can be =, >, >=, <, <=, <>. compare_operator可以是=,>,> =,<,<=,<>。 What you can do is
你能做的是
Take the difference between your supplied dates as follows 如下所示,提供您提供的日期之间的差异
Timestamp dateA ...
Timestamp dateB ...
Timestamp difference = new Timestamp(Math.abs(dateA.getTime() - dateB.getTime()));
And create a Timestamp which represents 4 minutes 并创建一个代表4分钟的时间戳
Timestamp fourMinutes = new Timestamp(0, 0, 0, 0, 4, 0, 0);
Now your query should looks like 现在你的查询应该是这样的
where :difference >= :fourMinutes
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.