Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR SQL

python sqlalcahmey compare datetime using AND_ or OR_

from datetime import datetime, timedelta
from sqlalchemy import and_

thirty_days_ago = datetime.today() - timedelta(days = 30)
fifteen_days_ago = datetime.today() - timedelta(days = 15)

# Using and_ IMPLICITLY:
payments = Payment.query.filter(Payment.due_date >= thirty_days_ago,
                                Payment.due_date <= fifteen_days_ago).all()

# Using and_ explicitly:
payments = Payment.query.filter(and_(Payment.due_date >= thirty_days_ago,
                                     Payment.due_date <= fifteen_days_ago)).all()
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #python #sqlalcahmey #compare #datetime
ADD COMMENT
Topic
Name
2+2 =