Friday, January 11, 2008

Date and DateTime comparisons in JPQL

JPQL doesn't have any explicit date conversion functions like the Oracle TO_DATE, but it does allow for direct comparisons with properly formatted date and datetime strings.


select m
from ClassM m
where m.dtval >= '2008-01-01 23:12:09' and m.dval < '2008-02-01'


This makes dynamic query generation somewhat simpler than having to use and set date parameters within the Query object (my original approach).

1 comment:

Freddy Paz Espinoza said...

Thanks a lot. I am working in a project with JSF, GlassFish, SQL Server 2005 and EJBeans :D and I was trying to compare different dates. Thanks :D