I have data, which I've formatted and sliced in the following format:
currentTime = datetime.now().strftime("%m-%d-%Y")
which returns dates such as this:
09-20-2017
I want to compare this date, or rather the timedelta of this date some time period back, let's say 7 days, so it would be:
09-13-2017
Now, my code says the following:
if currentTime.timedelta(days=7) < furtherSplit[0:10]:
Which ideally I'd like to activate when the currentTime, of timedelta 7, was an earlier date than the furtherSplit[0:10], which is another date, formatted in the same way, but cut from some segment of text, which has the date and another string. If I were to print furtherSplit[0:10], it returns a date like this:
09-18-2017
How would I get this to work? I have made sure timedelta was imported, and printed the individual dates to see they were working. However, when I do currentTime.timedelta(days=7), it does not print.
EDIT
On the help / request of Brad Solomon, here is an updated issue:
So, in using:
from dateutil.relativedelta import relativedelta
...
def compare_dates(date1, date2, **kwargs):
date1 = datetime.datetime.strptime(date1, '%m-%d-%Y')
date2 = datetime.datetime.strptime(date2, '%m-%d-%Y')
td = relativedelta(**kwargs)
return date1 - td < date2
...
if compare_dates(currentTime, furtherSplit[0:10], days=7):
someList.append(x)
print ("get here")
It never prints or appends the 'x' to someList. Everything being used is valid. Please advise!