In Python, if I wanted to do a check for all items from yesterday would I do something like:
from datetime import datetime, timedelta
if datetime.datetime.today() - timedelta(days=2) < item_to_check < datetime.datetime.today():
Would this pull all items from yesterday and is this the best way to do it?
I'd try something easier ;-)
from datetime import date, timedelta
yesterday = date.today() - timedelta(days=1)
if item_to_check.date() == yesterday:
# yup!
Note that your:
item_to_check < datetime.datetime.today()
is true for any item that occurred before the second you called datetime.datetime.today()
. My date.today()
doesn't include hours, minutes or seconds (i.e., it has no "time" component).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With