balu
balu

Reputation: 41

JPA: Convert date from one format to another

I am passing an argument of type DATE, and I need to compare it with a column in the DB which has the date format MM-DD-YY: HH:MM:SS, but I don't need the HH:MM:SS to be considered. What sort of JPA query would do this?

Upvotes: 2

Views: 6702

Answers (3)

Neil Stockton
Neil Stockton

Reputation: 11531

Most JPA implementations provide JPQL vendor extensions for YEAR, MONTH, DAY functions and you can compare those. Alternatively use JPA 2.1 "FUNCTION" and specify the native SQL function for extracting the YEAR, MONTH, DAY for that column.

Upvotes: 1

Aniket
Aniket

Reputation: 173

using @Temporal annotation you can take only date

 @Temporal(TemporalType.DATE)
 private java.util.Date date;

Upvotes: 0

Smutje
Smutje

Reputation: 18123

Extract all rows from <table> where <column> contains '2015-05-07' and an arbitrary time extension:

select * from <table> where date(<column>) = '2015-05-07'

Upvotes: 0

Related Questions