0

How to write query in Hibernate SQL or HSQL to show one week data or 1month data from current date?

  • Already answered at http://stackoverflow.com/questions/2856386/java-jpql-date-function-to-add-a-time-period-to-another-date – Gregory Klimov Oct 14 '13 at 14:50

1 Answers1

0

Consider an Entity Product with _productId and _productCreatedDate So the

StringBulider sql=new StringBuilder();
sql.append("select _productId,_productCreatedDate from Product where");
sql.append("_productCreatedDate between :currentDate and :dateOneMonthBefore")
sessionFactory.getSession().createQuery(sql.toString()).setParameter("currentDate",newDate())
 .setParameter("dateOneMonthBefore",new Date("Enter the month before the current date"))
BholaVishwakarma
  • 581
  • 6
  • 18