How to Subtract number of days from current date in HQL query
You can use date_Sub in a native SQL query (not a HQL query!):
"from Users where createdDate = DATE( DATE_SUB( NOW() , INTERVAL 21 DAY ) )"
The solution with HQL is quite simple:
final long time = System.currentTimeMillis() - java.time.Duration.ofDays(21).toMillis();
final javax.persistence.Query query = entityManagerOrSession.createQuery(
"SELECT x FROM users x WHERE x.createddate> :time");
query.setParameter("time", new java.sql.Timestamp(time));