Hibernate query date compare on year and month onl

2019-02-14 23:37发布

问题:

I need to grab some records from a table which has a Column birthDate which is a Date(without time). I need to filter records by comparing against year and month only. For example I want all the users born on March of 1990. The day doesn't matter.

How do you handle it?

回答1:

You can use from Entity where to_char(birthDate,'YYYY/MM') = '1990/03' this will work for HQL



回答2:

you may try this

 select * from table where month(birthdate)=03 and year(birthdate)=1990