tags:

views:

159

answers:

1

Hi, I'm trying to make a query function that accepts two datetime.date object(start_date and end_date), and return all records with a related field that's between start_date and end_date. However, I found nothing like a between function in the web2py manual, so I implement it this way:

        for o in objects:
            # notice that create_time is a datetime field
            create_date = dt.datetime.strptime(o['create_time'], 
                                               "%Y-%m-%d %H:%M:%S").strftime("%Y-%m-%d")
        if query_dict['create_date_1'] <= create_date <= query_dict['create_date_2']:
            result.append(l)

Doing this is too slow for my application because their can be many objects. So, is there a better way I can implement this using web2py.DAL? Thanks in advance ;)

A: 

db((db.mytable.create_date>=query_dict['create_date1'])&(db.mytable.create_date<=query_dict['create_date2'])).select()

mdipierro
In my case, the queried field is of type datetime, so I solve this problem by first converting the two arguments to datetime object and then make a query similar to yours.Thank you.
Satoru.Logic