[rules-users] issue with date comparison

Wolfgang Laun wolfgang.laun at gmail.com
Thu Jun 21 08:04:44 EDT 2012


On 21/06/2012, sumatheja <sumatheja at gmail.com> wrote:
> Hi,
>    I've a fact which is retrieved from database using hibernate. The date
> format that comes in is "yyyy-mm-dd", java.util.Date. The fact has two
> variables *startDate* and *endDate. *I want to check if the the *current
> date* lies between these two. Since the current date is not constant I'm
> trying to use a global variable, which I would setbefore firing the rules.
> My question is what should be the datatype of this global variable. If I
> use Date the format is completely different.

What do you mean by "the format is completely different".
java.util.Date doesn't have a "format".

> If I use String it says that
> date can't be compared with string.
>
>     However if I hard code the value of current date in "*dd-MMM-yyyy*"
> rule fire fine. Can someone please suggest me a way to achieve this. Thanks
> in advance.

Use java.util.Date for the global "today". Compare the "long" values
returned from getTime, e.g.,
   Fact( startDate.time >= today.getTime() )

-W

>
> --
> cheers
> Sumatheja Dasararaju
>


More information about the rules-users mailing list