【发布时间】:2017-08-22 11:33:22
【问题描述】:
我有两个日期字段 campaign_start_date 和 campaign_end_date。我想计算每个月介于campaign_start_date 和campaign_end_date 之间的天数。
例如:
campaign_start_date = September 7 2017
campaign_end_date = November 6 2017
解决方案应该是:
Total No:of days = 61 days
No: of months = 3 months
Month 1 = 9/7/2017 to 9/30/2017
Month 2 = 10/1/2017 to 10/31/2017
Month 3 = 11/1/2017 to 11/6/2017
No:of days in Month 1 = 24 days
No:of days in Month 2 = 31 days
No:of days in Month 3 = 6 days
如何使用 Python 实现这一点? 到目前为止,我已经取得了:
@api.multi
def print_date(self):
start_date = datetime.strptime(self.start_date, "%Y-%m-%d %H:%M:%S")
end_date = datetime.strptime(self.end_date, "%Y-%m-%d %H:%M:%S")
campaign_start_date = date(start_date.year,start_date.month,start_date.day)
campaign_end_date = date(end_date.year,end_date.month,end_date.day)
duration = (campaign_end_date-campaign_start_date).days
return True
【问题讨论】:
-
我得到了总天数
标签: python-2.7 ubuntu odoo-10 odoo-accounting