0

such as

date_sub(curdate(), interval 7 day)

i find a solution Hql / jpql date arithmetic but there is no following

edcjian
  • 77
  • 1
  • 7
  • 1
    Is your question the same with that purpose? My understanding is his question is about to compare the dates in where condition, while your question is about how to sub 7 days. – Tuan Hoang Jun 27 '21 at 09:25
  • same as it,i just want know how to do date calculate in hql – edcjian Jun 27 '21 at 14:27
  • 1
    I added my answer here, hope it helps https://stackoverflow.com/questions/19813973/hql-jpql-date-arithmetic/68152225#68152225 – Tuan Hoang Jun 27 '21 at 14:39
  • I have to accept the fact that there is no perfect solution. If you want to map dto conveniently, you have to give up MySQL date function – edcjian Jun 27 '21 at 14:54
  • Yes, to use the power of built in function of MySQL, let's use `native query`. For customization, use constructor instead. For data mapping, you can use `ModelMapper` also. And with `DateTime` from MySQL, I usually create some helper to convert the date. – Tuan Hoang Jun 27 '21 at 15:17

1 Answers1

0

You can't use that directly in HQL/JPQL. You have to register a custom SQL function that renders this SQL.

Christian Beikov
  • 15,141
  • 2
  • 32
  • 58