java - How to Subtract number of days from current date in HQL query -
i using hql data inserted exact 21 days now. here code
query querythreeweek = session.createquery("from users createddate = curdate()-21"); list<users> userdetailsthreeweeklist = querythreeweek.list();
i can not use createsqlquery
. right not getting data, there data date 2016-06-20
. , because of month changed because when used curdate()-7
got correct data of date 2016-07-04
. calculation dat like;
2016-07-11 - 7 = 20160704 2016-07-11 - 21 = 20160690
i tired using interval
native sqlquery
. here code using interval
in hql:
query querythreeweek = session.createquery("from users createddate = date( date_sub( now() , interval 21 day ) )"); list<users> userdetailsthreeweeklist = querythreeweek.list();
also tried
query querythreeweek = session.createquery("from users createddate = date( date_sub( curdate() , interval 21 day ) )"); list<users> userdetailsthreeweeklist = querythreeweek.list();
but giving me exception like: org.hibernate.hql.internal.ast.querysyntaxexception: unexpected token: 21
.
so can use instead of subtracting day this: curdate()-21
? in hql only
you can use date_sub
"from users createddate = date( date_sub( now() , interval 21 day ) )"
Comments
Post a Comment