c# 一个月中的工作日_在Excel中查找一个月中的第N个工作日

c# 一个月中的工作日

Some events occur on the Nth weekday of a specific month each year. Maybe your book club meets on the 4th Tuesday every month, and you don't want to miss any meetings. In Excel, you can use a formula to find the Nth weekday in a month, and there's an example shown below.

某些事件发生在每年特定月份的第N个工作日。 也许您的读书俱乐部每个月的第四个星期二开会,而您不想错过任何会议。 在Excel中,您可以使用公式来查找一个月中的第N个工作日,下面显示了一个示例。

一个月的第N个工作日 (Nth Weekday in a Month)

Aside from your book club, there are other event that always occur on the Nth weekday in a month.

除了您的读书俱乐部,还有其他活动总是在一个月的第N个工作日发生。

For example, here in Canada, we celebrate Victoria Day on the 3rd Monday in May, and in the USA. Thanksgiving is the 4th Thursday in November.

例如,在加拿大,我们将在5月的第三个星期一和美国庆祝维多利亚日。 感恩节是十一月的第四个星期四。

第N个工作日公式 (Nth Weekday Formula)

You can find the "Nth weekday in a month" dates in Excel, using a couple of Excel's  date functions – WEEKDAY and DATE.

您可以使用几个Excel的日期函数WEEKDAY和DATE在Excel中找到“一个月的第N个工作日”日期。

Here's a screen shot of my sample file, with the named ranges that I created.

这是我的示例文件的屏幕截图,其中包含我创建的命名范围

calculate nth weekday in month

Here's the formula in cell C9, to calculate the 4th Thursday in November 2020. The formula uses the defined names, instead of cell references:

这是单元格C9中的公式,用于计算2020年11月的第4个星期四。该公式使用定义的名称,而不是单元格引用:

=DATE(SelYr,SelMth,1 + ((SelN-(SelWD>= WEEKDAY(DATE(SelYr,SelMth,1)))) *7) + (SelWD- WEEKDAY(DATE(SelYr,SelMth,1))))

= DATE(SelYr,SelMth,1 +((SelN-(SelWD> = WEEKDAY(DATE(SelYr,SelMth,1)))))* 7)+(SelWD- WEEKDAY(DATE(SelYr,SelMth,1)))))

NOTE: That formula is based on the late Chip Pearson's nth day example. Chip's site shows the formula, but doesn't explain how it works, so I made a page on my Contextures site, with details.

注意 :该公式基于Chip Pearson已故的第n天示例 。 Chip的网站上显示了该公式,但没有说明其工作原理,因此我在Contextures网站上做了一个页面,并提供了详细信息。

这个怎么运作 (How It Works)

First, the Nth weekday formula calculates the 1st of the month date, with the DATE function.

首先,第N个工作日公式使用DATE函数计算每月的第1个日期。

  • DATE(SelYr,SelMth,1)

    DATE(SelYr,SelMth,1)

It also calculates the weekday number for that month start date, using the WEEKDAY function:

它还使用WEEKDAY函数计算该月开始日期的工作日编号:

  • WEEKDAY(DATE(SelYr,SelMth,1)

    WEEKDAY(DATE(SelYr,SelMth,1)

查找第N次出现 (Find the Nth Occurrence)

Next, the formula checks if the 1st occurrence is in the month's 1st week, by comparing the 1st's weekday number, to the target weekday number.

接下来,该公式通过将第一个工作日的数字与目标工作日数字进行比较,来检查第一个事件是否在月份的第一个星期。

  • If the 1st occurrence is in the 1st week, the formula adds (N-1) * 7 days to the start date

    如果第一次出现在第一周,则公式将(N-1)* 7天添加到开始日期
  • If the 1st occurrence is NOT in the 1st week, the formula adds (N-0) * 7 days to the start date

    如果第一次不在第一周,则公式将(N-0)* 7天添加到开始日期

In November 2020, the 1st Thursday is in the 1st week, so 21 days are added, to get to the week with the Nth occurrence:

在2020年11月,第一个星期四在第1周,因此增加了21天,直到出现第N个事件:

  • (4-1) * 7 = 21

    (4-1)* 7 = 21

查找工作日 (Find the Weekday)

Next, the formula adds or subtracts days, based on the weekday numbers.

接下来,公式将根据工作日的数字添加或减去天数。

  • If the target weekday is less than the month start weekday, days are subtracted

    如果目标工作日小于开始月份的月份,则减去天数
  • If the target weekday is the same as the month start weekday, zero days are added

    如果目标工作日与月份开始工作日相同,则添加零天
  • If the target weekday is greater than the month start weekday, days are added

    如果目标工作日大于月份开始的工作日,则添加天数

In November  2020, the 1st is on a Sunday (weekday 1) and the target day is a Thursday (weekday 5). The formula adds 4 days:

2020年11月,第一天是星期日(工作日1),目标日期是星期四(工作日5)。 该公式将增加4天:

  • 5 – 1 = 4

    5 – 1 = 4

第N个工作日公式结果 (Nth Weekday Formula Result)

For November 2020, the 4th Thursday is on the 26th. Here's the formula, with the numbers used to calculate that date:

对于2020年11月,第4个星期四位于26日。 这是公式,其中包含用于计算该日期的数字:

  • 1 + ((4-1) * 7) + 4 = 26

    1 +((4-1)* 7)+ 4 = 26

find the nth weekday in month

获取样本文件 (Get the Sample File)

For more details on the formula, and a sample file, go to the Nth Weekday page on my Contextures site.

有关公式和示例文件的更多详细信息,请转到Contextures网站上的“第N个工作日”页面

翻译自: https://contexturesblog.com/archives/2020/03/12/find-the-nth-weekday-in-a-month-in-excel/

c# 一个月中的工作日

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值