Convert date to string in Hibernate Criteria

前端 未结 2 1684
隐瞒了意图╮
隐瞒了意图╮ 2021-01-21 10:26

Is it possible to perform a request that checks the string representation of a Date instance. For example

Restrictions.like(\"dateField\", \"%12%\") 

2条回答
  •  抹茶落季
    2021-01-21 10:50

    Something like this

    
    Restrictions.sqlRestriction("month(dateField) = 12");
    Restrictions.sqlRestriction("right(year(dateField),2) = 12");
    

    The part within the sqlRestriction depends on which database you are using.

提交回复
热议问题