I'm doing queries find all the dates within last 6 months using Python and SQLAlchemy. The code is as following,
current_time = datetime.datetime.utcnow()
six_months_ago = current_time - datetime.timedelta(weeks = 24)
puppies = session.query(Puppy).filter(Puppy.dateOfBirth > six_months_ago).all()
for puppy in puppies:
You'll need to use python-dateutil:
from datetime import date from dateutil.relativedelta import relativedelta six_months = date.today() + relativedelta(months=+6)
There doesn't appear to be a way to do this with the out-of-the-box tools.