Matthew,
This is some code that works for me. It checks if the current date is
between two columns, you could switch it around.
Criteria criteria = new Criteria();
SimpleDateFormat formatter
= new SimpleDateFormat ("yyyy-MM-dd kk:mm:ss");
String currentDate = new String(formatter.format(new Date()));
criteria.add( WeekPeer.STARTS, (Object)currentDate,
Criteria.LESS_EQUAL );
criteria.add( WeekPeer.ENDS, (Object)currentDate,
Criteria.GREATER_THAN );
return (Week) WeekPeer.doSelect(criteria).firstElement();
regards
Dave Meaker
> -----Original Message-----
> From: Matthew Forder [mailto:[EMAIL PROTECTED]]
> Sent: 05 September 2001 07:44
> To: [EMAIL PROTECTED]
> Subject: Criteria - select between 2 dates
>
>
> I'm trying to build a query where records are selected when a column
> containing a date falls between 2 user supplied dates. The code I'm
> using looks something like this (the names have been changed
> to protect
> the innocent):
>
> Criteria criteria = new Criteria();
> Vector victor = new Vector();
> Criteria.Criterion a = criteria.getNewCriterion(SomePeer.CREATED_DATE,
> new GregorianCalendar(fyy, fmm, fdd), Criteria.GREATER_EQUAL);
> Criteria.Criterion b = criteria.getNewCriterion(SomePeer.CREATED_DATE,
> new GregorianCalendar(tyy, tmm, tdd), Criteria.LESS_EQUAL);
> criteria.add(a.and(b));
> victor = SomePeer.doSelect(criteria);
>
> However, when I try to execute the query, the SQL that is being
> generated contains (what looks like) a serialized copy of the
> GregorianCalendar objects, rather than something that looks
> like a date.
>
> Reading from the Turbine API and looking at the source code for
> org.apache.turbine.util.db.Criteria I think I'm taking the right
> approach, but of course on the other hand I'm probably doing something
> dumb.
>
> Any help on this one is appreciated!!
>
> Thanks and regards,
>
> Matt
>
> --
> ____ | Matthew J. Forder | Data Center Supervisor
> / / () | Seagate Techology | Tel:+31 20 316 7468
> \ \ \ | Koolhovenlaan 1 | Fax:+31 20 653 5537
> ()_/_/ | 1119 NB Schiphol-Rijk, NL | [EMAIL PROTECTED]
>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]