0
CriteriaBuilder builder = session.getCriteriaBuilder();
CriteriaQuery<Star> criteriaQuery = builder.createQuery(A.class);
Root<Star> root = criteriaQuery.from(A.class);

I am already having MONDAY of the week and FRIDAY of the week and then check the today's date lies between MONDAY and FRIDAY of the week.

I have use before and after method thats not working for me.

  • just use new Date(); – Mostch Romi Dec 21 '18 at 05:53
  • Refer This: https://stackoverflow.com/questions/4256561/using-jpa-hibernate-criteria-to-pull-between-a-date. Might be helpful – Ankur Dec 21 '18 at 05:54
  • you said you already having Monday and friday. this information is stored in database. Monday and Friday is stored in in some columns like startDate and EndDate . you want to check that if current date lied between these days ? Am i right ? – Khalid Shah Dec 21 '18 at 06:12
  • I am able to get current date now, Monday and Friday as well but problem is i am not able to compare and check whether current date lies between Monday and Friday. –  Dec 21 '18 at 06:14

1 Answers1

-1

Try this. use cb.currentTime() or cb.currentTimestamp()

CriteriaBuilder builder = session.getCriteriaBuilder();
CriteriaQuery<Star> criteriaQuery = builder.createQuery(A.class);
Root<Star> root = criteriaQuery.from(A.class);
// Add this condition
List<Predicate> conditions = new ArrayList<>();
conditions.add(cb.equal(root.get("Your  time column name"),cb.currentTimestamp()));
cq.where(conditions.toArray(new Predicate[]{}));
Query query=session.createQuery(cq);
Khalid Shah
  • 3,132
  • 3
  • 20
  • 39
  • because this is comparison with current timestamp, not with date. Most probably OP search something like `where date(table.created_timestamp) = date(now())` – degr Dec 12 '19 at 08:25