I want to know if insertion_date
is older than 30 days. This should detect down to the minute and second of the current time. The value in insertion_date
will be dynamically pulled from an API.
Current code only detects up to the day, i need the accuracy to up to the second.
import datetime
import dateutil.parser
insertion_date = dateutil.parser.parse('2017-08-30 14:25:30')
right_now_30_days_ago = datetime.datetime.today() - datetime.timedelta(days=30)
print right_now_30_days_ago #2017-08-31 12:18:40.040594
print insertion_date #2017-08-30 14:25:30
if insertion_date > right_now_30_days_ago:
print "The insertion date is older than 30 days"
else:
print "The insertion date is not older than 30 days"
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…