How to Subtract number of days from current date in HQL query
<p>I am using HQL to get the data inserted exact 21 days from now. Here is my Code</p>

<pre><code>Query queryThreeWeek = session.createQuery("from Users where createdDate = CURDATE()-21");
List&lt;Users&gt; userDetailsThreeWeekList = queryThreeWeek.list();
</code></pre>

<p>I can not use <code>createSQLQuery</code>.
Right now I am not getting any data, but there is data for the date <code>2016-06-20</code>. And that is because of the month changed because when I used <code>CURDATE()-7</code> I got the correct data of the date <code>2016-07-04</code>.
The calculation for dat is like;</p>

<pre><code>2016-07-11 - 7 = 20160704
2016-07-11 - 21 = 20160690
</code></pre>

<p>I also Tired using <code>INTERVAL</code> which is for <code>native sqlQuery</code>. Here is my code for using <code>INTERVAL</code> in HQL: </p>

<pre><code>Query queryThreeWeek = session.createQuery("from Users where createdDate = DATE( DATE_SUB( NOW() , INTERVAL 21 DAY ) )");
List&lt;Users&gt; userDetailsThreeWeekList = queryThreeWeek.list();
</code></pre>

<p>Also tried</p>

<pre><code>Query queryThreeWeek = session.createQuery("from Users where createdDate = DATE( DATE_SUB( CURDATE() , INTERVAL 21 DAY ) )"); 
List&lt;Users&gt; userDetailsThreeWeekList = queryThreeWeek.list();
</code></pre>

<p>but it is giving me exception like: <code>org.hibernate.hql.internal.ast.QuerySyntaxException: unexpected token: 21</code>.</p>

<p>So what can I use instead of subtracting the day like this: <code>CURDATE()-21</code>? in HQL only</p>