Hi,

I can't find a usable reference to selecting records from a database
table based on the value of datetime fields. Here's my situation:

I have a table with two date fields:

    db.define_table("announcements",
        SQLField("validfrom", "datetime", notnull=True,
default=datetime.today(), label="Valid from"),
        SQLField("expires", "datetime", notnull=True,
default=datetime.today()+timedelta(days=3), label="Expires"),
        SQLField("author_id", db.auth_user, default=session.user_id),
        SQLField("subject", "string", length=100, notnull=True,
label="Subject"),
        SQLField("message", "text", notnull=True, label="Message"))

I want to select records that are valid as follows:

anns = db( ( db.announcements.validfrom<datetime.today() ) and \
    ( db.announcements.expires>datetime.today() ) ) .select()

That is, expires date is in the future and the validfrom date is in
the past.

This code doesn't seem to work, as all records are returned,
regardless of the date values.

This must be a common requirement - any suggestions?

Reply via email to