• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2407
  • Last Modified:

Hibernate (HQL) date function issue

Hi,
I am trying to query some data from DB2 database by using HQL. Basically I am trying get previous day records.
The following where condition is working fine when i exceute in data studio (DB2 client/IDE).
where (DAYS(CREATE_TS) = DAYS(CURRENT_DATE - 1 DAY))

In database CREATE_TS column was defined as TIMESTAMP.

But the same thing is not working with HQL. i tried several ways, i am getting SQLCODE=-182, SQLSTATE=42816 (Explanation: A date, time, or timestamp expression not valid).

Can anyone help me with this please ?

Thanks in Advance.
0
kcmuthyala2
Asked:
kcmuthyala2
  • 3
1 Solution
 
Ajay-SinghCommented:
Can you post hql query you are using here?
0
 
kcmuthyala2Author Commented:
I found solition for this.
HQL ..... where (abc.create_ts >= :startTime  and abc.create_ts <= :endTime )

        Calendar cal = Calendar.getInstance();          
        // Subtract 1 days from the calendar        
        cal.add(Calendar.DATE, -1);        
        cal.set(Calendar.HOUR_OF_DAY, 0);
        cal.set(Calendar.MINUTE, 0);
        cal.set(Calendar.SECOND, 0);
        Date startTime = cal.getTime();
       
        cal.set(Calendar.HOUR_OF_DAY, 23);
        cal.set(Calendar.MINUTE, 59);
        cal.set(Calendar.SECOND, 59);
        Date endTime = cal.getTime();
0
 
kcmuthyala2Author Commented:
I would like to give 400 ponits for my solution.
0
 
kcmuthyala2Author Commented:
I waited, i did not get answer intime from others, meanwhile i found solution.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now