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.

4
  • just use new Date(); Commented Dec 21, 2018 at 5:53
  • Refer This: stackoverflow.com/questions/4256561/…. Might be helpful
    – Ankur
    Commented Dec 21, 2018 at 5: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 ? Commented Dec 21, 2018 at 6: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.
    – user10796473
    Commented Dec 21, 2018 at 6:14

1 Answer 1

-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);
1
  • because this is comparison with current timestamp, not with date. Most probably OP search something like where date(table.created_timestamp) = date(now())
    – degr
    Commented Dec 12, 2019 at 8:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.