Re: Comparing two Dates in cayenne

From: Andrus Adamchik (andru..bjectstyle.org)
Date: Mon Apr 25 2005 - 21:49:21 EDT

  • Next message: Andrus Adamchik: "Re: Select *, perform generic query"

    Hi Denna,

    Generally you shouldn't attempt to include the dates into expression
    strings. This doesn't translate nicely into JDBC calls. Instead I
    suggest using ExpressionFactory passing it Date objects. E.g.:

        Expression e = ExpressionFactory.betweenExp(dateIn, d1, d2);

    This results in Cayenne passing d1 and d2 Date objects (not strings!)
    to the JDBC driver, thus hiding the details of date conversion to the
    right format for PostgreSQL.

    Andrus

    On Apr 25, 2005, at 5:48 PM, Dhruti Ramani wrote:
    > Hi,
    >  
    > I am using cayenne1.1 and postgresql7.* for as database. I have to get
    > all the rows from Deal table which has value of field "dateIn"(Date)
    > between startDate and endDate. The code I have used is this,
    >  
    > DateFormat df=DateFormat.getDateInstance(DateFormate.SHORT);
    > Date d1=df.parse(startDate);
    > Date d2=df.parse(endDate);
    > // to get in this format ::: query=dateIn > 'startDate' and dateIn <
    > 'endDate'
    > query="dateIn "+" > "+"'"+startDate+"'"+" and "+"dateIn"+" <
    > "+"'"+endDate+"'";
    > Expression e=Expression.fromString(query);
    > SeleceQuery q=new SelectQuery(Deal.class,e);
    > List alist=dataContext.performQuery(q);
    >  
    > But this returns the empty list even if the dataIn value is between
    > the specified range. If I use the same SQL format directly into
    > postgersql it returns the value.
    >  
    > Am I doing something wrong?
    >  
    > Thanks,
    > Denna



    This archive was generated by hypermail 2.0.0 : Mon Apr 25 2005 - 21:49:16 EDT