albemuth
albemuth

Reputation: 587

How to obtain CURDATE() / NOW() on a JPA named query?

I want to do a select from table where date = TODAY, on mysql that would be where date > CURDATE(), how do I do this on a JPA named query?

Upvotes: 26

Views: 59918

Answers (2)

ChssPly76
ChssPly76

Reputation: 100736

That depends on your JPA provider. Hibernate, for example, supports current_date function:

from MyEntity where myDateProperty > current_date

Upvotes: 34

McDowell
McDowell

Reputation: 108939

From the spec:

4.6.16.3 Datetime Functions

functions_returning_datetime:=
CURRENT_DATE |
CURRENT_TIME |
CURRENT_TIMESTAMP

The datetime functions return the value of current date, time, and timestamp on the database server.

Upvotes: 48

Related Questions