Thank you Brian!
It works perfectly. But there is one trouble.

If I use query with two dates:
   results=db(db.autos.dt<=d1 & db.autos.dt>=d2).select()
there is no result at all.

But if I use only first date:
   results=db(db.autos.dt<=d1).select()
there is correct result.

*************************************************************************************

On 27 апр, 01:15, Brian M <[email protected]> wrote:
> Tell web2py that those fields are supposed to be dates and it'll take care
> of the date format for you.
>
> Here's a form I use for finding stats between two dates, should be easy
> enough to modify for your purposes
>
> form = FORM(TABLE(TR(TD("First Date:"),
>                     TD(
>                         INPUT(_type="text",
>                             _name="start_date",
>                             _id="start_date",
>                             _class='date',
>                             _value=start_date,
>                             requires=[IS_DATE(error_message="Invalid Date
> Entered")]))),
>                 TR(
>                     TD("Second Date:"),
>                     TD(INPUT(_type="text",
>                         _name="end_date",
>                         _id="end_date",
>                         _class='date',
>                         _value=end_date,
>                         requires=[IS_DATE(error_message="Invalid Date
> Entered")]))),
>                 TR(INPUT(_type="submit", _value="Get Stats"))))
>
> Then when you validate the form, your dates will be converted to python date
> objects for you & your query should work.
>
> if form.accepts(request.vars, session, keepvalues=True):
>         start_date = form.vars.start_date
>         end_date = form.vars.end_date

Reply via email to