如何编写 Hibernate Criteria 以仅在两个日期和月份而不是年份之间获取记录

How to write Hibernate Criteria to get records only between two date and month not year

我正在创建一个应用程序,让用户输入他们的出生日期 (dd/mm/yyyy)。

我需要的是获取依赖于月份和日期而不是年份的记录。

例如:

  1. 1993 年 1 月 1 日

  2. 1995 年 8 月 1 日

  3. 2015 年 1 月 30 日

如果用户搜索两个日期之间的下一个出生日期

我需要显示前两条记录。

谁能帮忙。

需要使用DATE_FORMAT和SqlRestriction。

String sqlWhere = " DATE_FORMAT( " + "{alias}.date_of_birth"+ ",'%m-%d') BETWEEN '" + 
String.format("%02d", fromMonth) + "-" + 
String.format("%02d", fromDate)  +  "' and  '" + 
String.format("%02d", endMonth) + "-" +
String.format("%02d",  endDate )+ "'" ;
criteria.add(Restrictions.sqlRestriction(sqlWhere )  );