How can I use Datediff() in HQL

后端 未结 1 2042
攒了一身酷
攒了一身酷 2021-01-25 18:43

I\'m trying to get the difference between dates. In my SQL SERVER it\'s works fine:

Select CSERVICE_ORDER_ID 
FROM TSERVICE_ORDERS 
WHERE DATEDIFF(DAY, CDB_CREAT         


        
相关标签:
1条回答
  • 2021-01-25 19:30

    HQL doesn't support datediff, but if you still want to use datediff, you should use createNativeQuery() or createSQLQuery() to write that in sql. In your example, you just need the id anyway, not entity object, so this should be enough.

    or you can use in hql something like this, but the precission is a bit tricky if you record the datetime(not only date).

    4>(((CDB_CREATE_DATE_TIME - CCANCELLATION_DATE)/24/60/60/10)-1)>3
    

    /24/60/60/10 is hours in 1 day, minute in 1 hour, second in 1 minute and 10 is the precission i think (1/10s), cz i get 69.44444444444445 for 6 days different if i dont devide with 10 and put -1 at the end

    0 讨论(0)
提交回复
热议问题