Putting current date through IQuery
Hi,
I am trying to build a query in Agile to fetch the items that are released in last 7 days.
IQuery query = (IQuery)session.createObject(IQuery.OBJECT_TYPE,”SELECT ” +
“[Title Block.Number]” +
“FROM ” +
“[Items] ” +
“WHERE ” +
“[Title Block.Rev Release Date] >= DATE -7”); geeting syntax error at the place of DATE -7. Can anyone please help.
Thanks!
-Nagma
Hi Nagma,
Can you please explain these lines. What exactly happening at these statements.
Calendar cal = Calendar.getInstance();
cal.add(Calendar.DATE, -7);
Date dateToUse= cal.getTime();
IQuery query = (IQuery)session.createObject(IQuery.OBJECT_TYPE,”Select [Title Block.Number] FROM [Items] where [Title Block.Rev Release Date] >= %1″);
query.setParams(new Object[]{dateToUse});
– Thanks in advance
the Date is not a valid field to be passed. at least you can use $TODAY as parameter to get the today date and put it to the query.
The problem is that via SDK is not possible to use $TODAY-7 because it will generate further syntax error.
To do that, you have to create custom Date field using JAVA and retrieve last 7 days as below:
Calendar cal = Calendar.getInstance();
cal.add(Calendar.DATE, -7);
Date dateToUse= cal.getTime();
IQuery query = (IQuery)session.createObject(IQuery.OBJECT_TYPE,”Select [Title Block.Number] FROM [Items] where [Title Block.Rev Release Date] >= %1″);
query.setParams(new Object[]{dateToUse});
query.execute();