views:

35

answers:

1

so lets say I have a simple class Final and I want to filter the results for the past 2 days by the created field, how do I do this? When I populate the final class it has a utc created time, but I need the difference of that time and currently this is along the line of what I want done below, but I am unsure on how to get a difference in a query for all items?

class Final(db.Model):
    name = db.StringProperty()
    created = db.DateTimeProperty()

now = datetime.datetime.now()
##d = now - created
##if d.days > 2:
    ## I could loop along something like this but that would be too slow


results = Final.all()
results.filter('created =',##what do i do here?) ##would created >, and then now - 2days work?
+3  A: 

I would try:

results.filter('created > ', now - datetime.timedelta(days=2))
DiggyF