Try

fromdate = request.now.date()-datetime.timedelta(7)
rows = db(db.post.created_on > fromdate).select(...)


On Jan 23, 1:47 pm, dominatus <[email protected]> wrote:
> After testing the results in the shell, I can't believe Web2py keeps
> throwing an (!) error that the date is not in %Y-%m-%d format (!) (or
> %Y-%m-%d %H:%M:%S.%f for datetime), when it clearly is in the shell.
> I have tried several different methods, with the most logical (in my
> opinion) being:
>
> top10_weekly_query = db((datetime.date.today() -
> time.strptime(str(db.post.created_on), "%Y-%m-%d")) <= timedelta(days
> = 7)).select(db.post.ALL, orderby = ~db.post.rating)
>
> Where db.post.created_on is of type "date"
>
> I also tried converting using
> datetime.fromtimestamp(time.mktime(time.strptime(str(db.post.created_on),
> "%Y-%m-%d %H:%M:%S.%f"))) in place of the simpler method above, with
> db.post.created_on of type "datetime."
>
> This is all an attempt to get the posts only created within the last
> week, from "today/now."  I know I can sort this easier after pulling
> all the records, but I am trying to do this as efficiently as possible.

Reply via email to