简体   繁体   English

计算范围内的特定天数

[英]Calculate number of specific days in range

How can I count the (fractional) count of specific day of the week in a range? 如何计算范围内特定星期几的(小数)计数? For instance, if the range is from Monday, June 3 12:00 PM to Tuesday June 4 12:00 PM, and I want to count the number of Mondays, the formula would return the result 0.5. 例如,如果范围是从星期一,6月3日中午12:00到星期六6月4日中午12:00,我想计算星期一的数量,公式将返回结果0.5。

I've already found a formula for the integer number of days: 我已经找到了整数天的公式:

=SUM(INT((WEEKDAY($B2-x)+$D2-$B2)/7))

where x is the day of the week of interest (1 to 7). 其中x是感兴趣的星期几(1到7)。 Of course, it would need to be modified to return the aforementioned result. 当然,需要修改它以返回上述结果。 How would I do so? 我该怎么办?

You can get the total number of Mondays (including both start and end date) with this version (you don't need SUM) 您可以使用此版本获取星期一的总数(包括开始日期和结束日期)(您不需要SUM)

=INT((WEEKDAY($B2-2)+INT($D2)-INT($B2))/7)

...and then do an adjustment to take into account the start/end days, eg ...然后进行调整以考虑开始/结束日期,例如

=INT((WEEKDAY($B2-2)+INT($D2)-INT($B2))/7)-IF(WEEKDAY($D2)=2,1-MOD($D2,1))-IF(WEEKDAY($B2)=2,MOD($B2,1))

I don't really recommend it (it's much more resource-hungry) but this version should give you the same result 我不是真的推荐它(它需要更多的资源)但是这个版本应该给你相同的结果

=SUMPRODUCT((TEXT(B2+(ROW(INDIRECT("1:"&ROUND((D2-B2)*1440,0)))-0.5)/1440,"ddd")="mon")+0)/1440

It tests every minute within the date range to ascertain whether or not it falls on a Monday (assumes that you don't go down to seconds) 它测试日期范围内的每一分钟,以确定它是否落在星期一(假设你没有下降到秒)

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

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