You could always put the date in one field and the time in another. Then you can easily search on date or time.
On Jun 28, 8:09 pm, Niphlod <[email protected]> wrote: > you can always write a function if you are using this query a lot of > times.... > > if you have a field with "datetime" you must "inspect" it by > datetime(s) values.... if you're going to use only the "date" > information, you'd better be using "date" type for the field. > > anyway, you can end up with > > import datetime > def query_by_date(dt): > date_start = dt.date() > date_end = date_start + datetime.timedelta(days=1) > return date_start, date_end > > and write > timeframe = query_by_date(request.now) > t = db.events > rows = db(t.created_on >= timeframe[0])(t.created_on < > timeframe[1]) > > everytime you need to. > > maybe more elegant....or not so much > > import datetime > def query_by_date(f, dt=request.now): > return (field >= dt.date()) & (field < dt.date() + > datetime.timedelta(days=1)) > > def test(): > t = db.events > rows = db(query_by_date(t.created_on)).select() > > it can get even more "nicer", I think, but this was just a 5 minute > trial :P > > On Jun 27, 1:29 pm, "David J." <[email protected]> wrote: > > > > > > > > > Thanks Kenneth; > > > I actually did it this way also but I thought there would be a more > > elegant way to achieve it. > > > Although I guess not. > > > Sometimes since DAL does so much for in simple ways; I thought perhaps > > there was a simple way of doing this as well > > > On 6/27/11 6:54 AM, Kenneth Lundstr m wrote: > > > > > How do I use DAL to query by exact date? > > > > db((db.events.created_on < datetime(date_of_day+1 > > > 0.00.00)&(db.events.created_on > datetime(date_of_day 0.00.00)).select() > > > > Or then you need to save even just the date of the event, not datetime > > > as created_on saves. > > > > I might be totally wrong but this should work. > > > > Kenneth > > > >> I tried > > > >> db(db.events.created_on == request.now.date).select() > > > >> but this returned no rows? > > > >> I also tried > > > >> db(db.events.created_on.date == request.now.date).select() > > > >> but that throws an exception > > > >> Thanks.

