-1

In python how to find the total number of days for the last 6 months ?

For example today is 7 November(7 days in this month), and in october there are 31 days and so on until the last 6 months, and now i need to find the total for all the days in a month(until the last 6 months) like

7(Nov) + 31(Oct) + 30(Sep) +... until the last 6 months from now

Shiva Krishna Bavandla
  • 25,548
  • 75
  • 193
  • 313

1 Answers1

3

with dateutil:

>>> from dateutil.relativedelta import relativedelta
>>> import datetime
>>> delta = relativedelta(months=6)
>>> six_month_away = datetime.date.today() - delta
>>> abs((six_month_away - datetime.date.today()).days)
184
alko
  • 46,136
  • 12
  • 94
  • 102