-2
for count in json_data['data']:
    exp = str(count['expires_on'])
    print(exp)

I have this piece of code that print me exp(date in format 2022-05-11). I need to create an if condition that compares these dates from get request with current date -30 days. I'm new in Python and try many ways, may anyone help?

nagyl
  • 1,644
  • 1
  • 7
  • 18
  • 1
    Does this answer your question? https://stackoverflow.com/questions/8142364/how-to-compare-two-dates – viam0Zah Jul 31 '20 at 22:04

1 Answers1

0

This should work:

from datetime import datetime, timedelta

exp = "2020-08-31"

if (datetime.strptime(exp, "%Y-%m-%d") - timedelta(days=30)).date() == datetime.now().date():
    print("Yes")
MisterNox
  • 1,445
  • 2
  • 8
  • 22