Lucas
Lucas

Reputation: 1279

How to get the records from the current month in App Engine (Python) Datastore?

Given the following entity:

class DateTest(db.Model):
    dateAdded = db.DateTimeProperty()
    #...

What would be the best way to get the records from the current month?

Upvotes: 2

Views: 611

Answers (2)

Dan Holevoet
Dan Holevoet

Reputation: 9183

There are a few ways you can do this. For example, using Query:

import datetime
from google.appengine.ext import db

q = db.Query(DateTest)

# This month
month = datetime.datetime.today().replace(day=1, hour=0, minute=0, second=0, microsecond=0)

q.filter('dateAdded >= ', month)
results = q.fetch(10)

Upvotes: 7

Tkingovr
Tkingovr

Reputation: 1418

You could try something like:

import datetime
now = datetime.datetime.now()

DateTest.gql("WHERE dateAdded.month:1", now.month)

Upvotes: 1

Related Questions