Hibernate Criteria for Dates

前端 未结 4 482
南方客
南方客 2020-11-30 04:54

In oracle I have dates in format

17-April-2011 19:20:23.707000000

I would like to retrieve all orders for 17-04-2011.

 SimpleDateFormat form         


        
4条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-11-30 05:22

    If the column is a timestamp you can do the following:

            if(fromDate!=null){
                criteria.add(Restrictions.sqlRestriction("TRUNC(COLUMN) >= TO_DATE('" + dataFrom + "','dd/mm/yyyy')"));
            }
            if(toDate!=null){               
                criteria.add(Restrictions.sqlRestriction("TRUNC(COLUMN) <= TO_DATE('" + dataTo + "','dd/mm/yyyy')"));
            }
    
            resultDB = criteria.list();
    

提交回复
热议问题