简体   繁体   English

Excel 使用月份和年份计算两个日期之间每月的天数

[英]Excel count days per month between two dates using both months and years

I would like to know how to calculate days of each month between two dates:我想知道如何计算两个日期之间每个月的天数:

A一个 B C C D D E F F G G
1 1 From To 01/12/20 20 年 1 月 12 日 01/01/21 21 年 1 月 1 日 01/02/21 21 年 1 月 2 日 01/03/21 21 年 1 月 3 日 01/04/21 21 年 1 月 4 日
:-- :-- :---------: :---------: :-----: :-----: :---------: :---------: :--------: :--------: :--------: :--------: :--------: :--------: :-------: :--------:
2 2 15/12/20 20 年 15 月 12 日 12/3/21 21 年 12 月 3 日 17 17 31 31 28 28 12 12 0 0

I have tried using a formula I found elsewhere on this website but it only picks up the relevant months from the column headers in row 1. I need it to pick up the years as well.我尝试使用我在本网站其他地方找到的公式,但它只从第 1 行的列标题中获取相关月份。我也需要它来获取年份。 I wonder if anyone is able to alter this formula to include years as well:我想知道是否有人能够改变这个公式以包括年份:

=SUMPRODUCT(--(MONTH(ROW(INDIRECT($A2 & ":" & IF($B2="",TODAY(),$B2))))=MONTH(C1))) =SUMPRODUCT(--(MONTH(ROW(INDIRECT($A2 & ":" & IF($B2="",TODAY(),$B2))))=MONTH(C1)))

Note: Row 1 Dates are dates and not text.注意:第 1 行日期是日期而不是文本。

Charles查尔斯

Try:尝试:

C2: =MAX(MIN(EOMONTH(C$1,0),$B2)-MAX(C$1,$A2)+1,0)

and fill across (and down) as needed.并根据需要填写(和向下)。

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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