Using TRUNC function in JPQL

If you are finding the TRUNC function is not working with your JPQL, then here is the solution. You can alternately use the FUNC function of JPQL to translate the TRUNC into JPQL. Here is the example.


Select o from Example o where FUNC('TRUNC', o.date) = ...



Hope this little trick will work with you.


Comments

D. said…
You have to notify people that it's only with JPA 2.1 and as "FUNCTION" done, you just killed my hopes...
Anonymous said…
Its is not taking the second parameter. I am trying to pass 'IW' like this

FUNC('TRUNC', o.date, 'IW')

It is throwing exception.
sac said…
This comment has been removed by the author.
Anonymous said…
God bless you. It does work.