I have a list of items issued last 365 days, last 90 days, etc. I need to check if days are in this range: today - previous 365 days, today - last 90 days.
I created a method that sorts strings with dates, but I do not know how to check the range from the current day to the last 365 days.
I want to ensure the dates are correct since I have to check them daily.
def sort_date_by_last_365_days(self):
elements = self.driver.find_elements(By.XPATH, '//span[@class ="date-content"]')
empty_list = []
for e in elements:
print(e.text)
for i in elements:
empty_list.append(i.text)
print(empty_list)
data = pd.DataFrame({'Date': empty_list})
print(data)
data['Date'] = pd.to_datetime(data['Date'])
data.sort_values(by='Date')
print(data)
return FrameworkResult(status=0)
The method gets all dates and sorts dates.
from datetime import datetime
from dateutil.relativedelta import relativedelta
date_to_check = datetime.strptime('2022-06-23', '%Y-%m-%d')
today = datetime.today()
print(date_to_check,today)
one_year_from_now = today - relativedelta(years=1)
if today >= date_to_check >= one_year_from_now:
print('ys')
You can use datetime + relativedelta and check between a range like year from today and today?