Looking for a sample ArcPy script I can modify for my use. Any suggestions?
Solved! Go to Solution.
Typo on my part, an extra minus in days=180 (updated original code):
date_past = datetime.now() - timedelta(days=180)
Perhaps (you could remove time from formatting, if desired):
from datetime import datetime, timedelta
date_past = datetime.now() - timedelta(days=180) # you can add/subtract as required
wc = "Field IS NULL AND DateField < DATE '{}'".format(date_past.strftime("%Y-%m-%d %H:%M:%S"))
print wc
# Field IS NULL AND DateField < DATE '2018-04-08 09:25:35'
The month and day are correct but the year is 2019 instead of 2018?
Typo on my part, an extra minus in days=180 (updated original code):
date_past = datetime.now() - timedelta(days=180)
Awesome! Thanks for your help on this.
I used the code you supplied but noticed it's returning everything 180 days or older. I only want results that fall exactly 180 days from current date.
arcpy.SelectLayerByAttribute_management(permits, "NEW_SELECTION", "Date_Accepted = date '{}' AND Fee_Paid Is NULL".format(notice.strftime("%Y/%m/%d")))
My bet is to change the < to = and you should be good to go:
wc = "Field IS NULL AND DateField = DATE '{}'".format(date_past.strftime("%Y-%m-%d %H:%M:%S"))
When dealing with date/time, I probably wouldn't use "=" in the query. See Joshua Bixby's second comment in this thread with ESRI's explanation.
After I read you post with 'between' I realized that..... thanks!
And after I re-read Esri's comment, I started thinking milliseconds. So "23:59:59" could also miss "23:59:59.9".