EntityConditions to lookup records between 2 dates

2011-07-21 Thread Justin Robinson
The following doesn't seem to work.

 Calendar calS = Calendar.getInstance();
 calS.set(Calendar.DAY_OF_MONTH, 25);
 calS.set(Calendar.MONTH, (calS.get(Calendar.MONTH)-1));
 Calendar calE = Calendar.getInstance();
 calE.set(Calendar.DAY_OF_MONTH, 25);
 Timestamp periodBeginning =
UtilDateTime.getTimestamp(calS.getTimeInMillis());
 Timestamp periodEnd = 
UtilDateTime.getTimestamp(calE.getTimeInMillis());


EntityCondition condition1 =
EntityCondition.makeCondition(EntityOperator.AND,
EntityCondition.makeCondition(invoiceTypeId,
EntityOperator.EQUALS, SALES_INVOICE),
EntityCondition.makeCondition(invoiceDate,
EntityOperator.LESS_THAN, periodEnd),
EntityCondition.makeCondition(invoiceDate,
EntityOperator.GREATER_THAN, periodBeginning));

This must be a fairly common task is there an EntityOperator for timestamps?

Thanks in advance.

-- 
Regards,
Justin
Venture-Net Research  Development


Re: EntityConditions to lookup records between 2 dates

2011-07-21 Thread Adrian Crum
I don't know why the EntityCondition isn't working, but I see something 
wrong in your calendar logic. Instead of subtracting one from the int 
constant, you should use the Calendar object's add method to subtract 
one month.


-Adrian

On 7/21/2011 2:23 PM, Justin Robinson wrote:

The following doesn't seem to work.

  Calendar calS = Calendar.getInstance();
 calS.set(Calendar.DAY_OF_MONTH, 25);
 calS.set(Calendar.MONTH, (calS.get(Calendar.MONTH)-1));
 Calendar calE = Calendar.getInstance();
 calE.set(Calendar.DAY_OF_MONTH, 25);
 Timestamp periodBeginning =
UtilDateTime.getTimestamp(calS.getTimeInMillis());
 Timestamp periodEnd = 
UtilDateTime.getTimestamp(calE.getTimeInMillis());


EntityCondition condition1 =
EntityCondition.makeCondition(EntityOperator.AND,
EntityCondition.makeCondition(invoiceTypeId,
EntityOperator.EQUALS, SALES_INVOICE),
EntityCondition.makeCondition(invoiceDate,
EntityOperator.LESS_THAN, periodEnd),
EntityCondition.makeCondition(invoiceDate,
EntityOperator.GREATER_THAN, periodBeginning));

This must be a fairly common task is there an EntityOperator for timestamps?

Thanks in advance.