EntityConditions to lookup records between 2 dates

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

EntityConditions to lookup records between 2 dates

justin.g.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
Reply | Threaded
Open this post in threaded view
|

Re: EntityConditions to lookup records between 2 dates

Adrian Crum-3
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.
>