[Zope-DB] Question on ZSQL and Dates

Charlie Reiman creiman@kefta.com
Wed, 23 Oct 2002 09:16:32 -0700


In my experience, it's best to leave date handling up to database whenever
possible.

select * from person where
(sysdate - person.birthdate) > (45*365.25);

Hopefully someone will have a better solution for you.

> -----Original Message-----
> From: zope-db-admin@zope.org [mailto:zope-db-admin@zope.org]On Behalf Of
> Charlie Clark
> Sent: Wednesday, October 23, 2002 8:15 AM
> To: zope-db@zope.org
> Subject: [Zope-DB] Question on ZSQL and Dates
>
>
> Hi,
>
> I've been struggling for a while with this one: I need to be able compare
> dates/ages in a ZSQL-query and don't seem to be able to do it right.
>
> table person
> name varchar(20),
> id int,
> birthdate date
>
> Now I want to be able to select all rows in the table for people who are
> currently over 45 years old.
>
> SELECT * FROM person
> WHERE
> 45 <= '<dtml-var expr="_.DateTime().Date()">' - person.birthdate
>
> but as this doesn't work, I know I'm doing something wrong.
> Any ideas? Searched all over so far but have yet to find anything helpful
> :-(
>
> Charlie
> --
> Charlie Clark
> Helmholtzstr. 20
> Dsseldorf
> D- 40215
> Tel: +49-211-938-5360
> GSM: +49-178-782-6226
>
> _______________________________________________
> Zope-DB mailing list
> Zope-DB@zope.org
> http://lists.zope.org/mailman/listinfo/zope-db
>