Restrictions Between for Date in Hibernate Criteria

前端 未结 4 1535
情书的邮戳
情书的邮戳 2020-12-05 18:17

Hello I am using hibernate in my example.For bean Table Audit Trial I want to fetch audit trial between a date range with inclusion of upper & lower limits. My code is l

4条回答
  •  广开言路
    2020-12-05 18:54

    add one more day to end date

     @Autowired
     private SessionFactory sessionFactory;
    
     String startDate = "2019-07-31 ";
     String endDate = "2019-08-24 ";
    
     Date fromDate = format.parse(fromDate);
    
     /* Add one more day to the end date*/
    
     Date to =format.parse(endDate);
     Calendar today = Calendar.getInstance();
     today.setTime(dateto);
     today.add(Calendar.DAY_OF_YEAR, 1);
    
     Date toDate= format.parse(format.format(today.getTime()));
    
     Criteria crit = sessionFactory.getCurrentSession().createCriteria(model.class);
     crit.add(Restrictions.between("dateFieldName", fromDate, toDate));
     List result = crit.list();
    

提交回复
热议问题