简体   繁体   中英

Calculate number of days for last 6months from today in python

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM