简体   繁体   English

在Excel中,如何计算日期范围之间的天数,仅计算一周中的特定天数

[英]In Excel, how to calculate # of days between a date range, counting only specific days of week

I'm trying to get # days between 2 dates, but had to count only days of the week specified per pair of dates in questions. 我试图在2个日期之间获得#天,但必须只计算问题中每对日期指定的一周中的几天。

For example: 例如:

Date of operation = 9/1/2013 and 5/16/2014 Days of the Week in operation = Monday, Wednesday, Friday 营业日期= 9/1/2013和5/16/2014营业的星期几=星期一,星期三,星期五

I want to calculate total number of days in actual operation, given the days in operation per week. 给定每周运行的天数,我想计算实际运行的总天数。

If you have Excel 2010 or later you can use NETWORKDAYS.INTL function which allows you to customise which days are counted, eg the following formula will count Mondays , Wednesdays and Fridays between a start date in A2 and an end date in B2 (inclusive) while excluding holiday dates listed in H2:H10 如果您具有Excel 2010或更高版本,则可以使用NETWORKDAYS.INTL函数,该函数可以自定义要计算的天数,例如,以下公式将对A2的开始日期和B2的结束日期(包括)之间的MondaysWednesdaysFridays进行计数但不包括H2:H10列出的假期

=NETWORKDAYS.INTL(A2,B2,"0101011",H$2:H$10)

The string "0101011" defines the days to include - 0 is included, 1 is excluded - it starts with Monday 字符串“ 0101011”定义要包含的日期-包括0,排除1-从星期一开始

In earlier excel versions you can use this formula for the same result 在早期的excel版本中,您可以使用此公式获得相同的结果

=SUMPRODUCT((WEEKDAY(ROW(INDIRECT(A2&":"&B2)))={2,4,6})*(COUNTIF(H$2:H$10,ROW(INDIRECT(A2&":"&B2)))=0))

where {2,4,6} defines the weekdays to include (1=Sun through to 7=Sat) 其中{2,4,6}定义要包含的工作日(1 =星期日至7 =星期六)

The number of days between to dates is just date1 - date2. 到日期之间的天数仅为date1-date2。

One method is to divide the number of days in operation by the number of days in the week. 一种方法是将工作天数除以一周中的天数。 In this case that would be 3/7. 在这种情况下,将是3/7。 In this example, the number of days in operation would be 110.14 days. 在此示例中,运行天数将为110.14天。 Below is your example. 以下是您的示例。 cell B4 has 1-sep-13, b6 has 16-may-14, both formatted as dates. 单元格B4的日期为13年9月1日,b6的日期为14年5月16日,均设置为日期格式。

    B
4   41518   

6   41775   

8   =B6-B4  Days
9   =B8/7   Weeks
10  =B8*3/7 

    01-Sep-13   

    16-May-14   

    257         Days
    36.71   Weeks
    110.14

To get more accurate, you would need to know which day of the week, weekday(), the first day in your range was and which day of the week your last day was. 为了获得更高的准确度,您需要知道星期几,weekday(),范围的第一天以及最后一天的星期几。

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

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