C# 如何确定Sql服务器中的公共假期?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/457176/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-04 04:06:35  来源:igfitidea点击:

How do I determine a public holiday in Sql server?

c#sqlsql-server

提问by HAdes

I have an application written in c# that cannot run on a public holiday or a weekend. I've looked around a bit and haven't found anywhere (official) that provides all the public holidays for the next say 50 years.

我有一个用 c# 编写的应用程序,它不能在公共假期或周末运行。我环顾四周,没有找到任何(官方)提供未来 50 年所有公共假期的地方。

If I can get these, I will simply bulk insert them into my sql server Holidays table and use that. However, I can't find this data anywhere.

如果我能得到这些,我将简单地将它们批量插入到我的 sql server Holidays 表中并使用它。但是,我无法在任何地方找到这些数据。

Does anyone know if Sql server has any support for public holidays or an algorithm of some sort to work them out? Or does anyone have somewhere official that I can bulk insert from.

有谁知道 Sql server 是否支持公共假期或某种算法来解决它们?或者有没有人有我可以批量插入的官方网站。

回答by Yuval Adam

Isn't a public holiday very dependent of locale?

公共假期不是非常依赖地点吗?

Programatically, there is no way to computethis. Alternatively, you will need to find an official list of holidays for each of your locales. And even so, you will not get the granularity you want.

以编程方式,没有办法计算这个。或者,您需要找到每个地区的官方假期列表。即便如此,您也不会获得所需的粒度。

回答by cbp

Public holidays are rarely available for the next 50 years. In some countries they are known for the next couple of years, in some countries not. They also vary by states and even cities.

在接下来的 50 年里很少有公共假期。在某些国家/地区,它们在接下来的几年中广为人知,而在某些国家/地区则不然。它们也因州甚至城市而异。

回答by Robin

As far as I know there isn't any 'official' source, and this is indeed highly dependent on locale. You'd have to manage these manually. A good source seems to be:

据我所知,没有任何“官方”来源,这确实高度依赖于语言环境。您必须手动管理这些。一个好的来源似乎是:

http://en.wikipedia.org/wiki/List_of_holidays_by_country

http://en.wikipedia.org/wiki/List_of_holidays_by_country

Even under these circumstances it's very tricky to manage. For example, I live in Belgium, and different parts of the country have different holidays. Government workers for example have different holidays compared to the rest of the workforce, and this is in the same locale code.

即使在这种情况下,管理起来也非常棘手。例如,我住在比利时,全国不同地区有不同的假期。例如,与其他工作人员相比,政府工作人员有不同的假期,这是在相同的区域设置代码中。

回答by MatBailie

In our applications we have it part of the user configuration. There is a place for users to set what they consider public/bank holidays for as far into the future as they want. For ease of use there is the ability to copy them by date from previous years. This also allows them to set 'custom' public holdays, perhaps a day that the company treats as a holiday but is not natioanlly official...

在我们的应用程序中,我们将其作为用户配置的一部分。有一个地方供用户根据需要设置他们认为的公共/银行假期。为便于使用,可以按前几年的日期复制它们。这也允许他们设置“自定义”公共假期,也许是公司将其视为假期但不是国家官方的一天……

Programatically, however, there are absolutely no assumptions at all. It's effectively just a user maintained table of dates.

然而,在编程上,绝对没有任何假设。它实际上只是一个用户维护的日期表。

(This includes the UK because, as stated above, some holidays vary and are not set in stone, and sometimes there are special one-off days.)

(这包括英国,因为如上所述,一些假期会有所不同并且不是一成不变的,有时还有特殊的一次性日子。)

回答by endian

Ahhh, holiday calendars. The bane of any investment bank programmer's life. There's no way of doing it other than maintaining your own list, I'm afraid!

啊,假期日历。任何投资银行程序员生活的祸根。恐怕除了维护自己的清单之外别无他法!

回答by Knox

In addition to allowing the user to configure what days are holidays, it would be nice if you allowed the user to select a calendar to import or even to subscribe to. iCalSharehas a nice list. However, it's probably too much work for a feature that's merely nice.

除了允许用户配置哪些天是假期之外,如果您允许用户选择要导入甚至订阅的日历,那就太好了。 iCalShare有一个不错的列表。然而,对于一个仅仅很好的功能来说,这可能是太多的工作。

回答by Nick Fortescue

To add what other people have already said, putting your own in a table is the only real way of doing it. A classic example is the extra bank holiday for the Queen's golden jubilee. This was only announced a couple of years in advance, and there was no way you could have it fifty years in advance.

添加其他人已经说过的内容,将自己的内容放在桌子上是唯一真正的方法。一个典型的例子是女王金禧的额外银行假期。这只是提前几年宣布的,不可能提前五十年。

Because of this a number of commercial services exist to provide this data in a reliable way. One is GoodBusinessDay.combut I have no experience with it.

因此,存在许多商业服务以可靠的方式提供这些数据。一个是GoodBusinessDay.com,但我没有这方面的经验。

回答by Mike Woodhouse

If it's just England, then you can work them out for yourself! You'll need to get a reliable algorithm for determining Easter, but otherwise I'd say you could do it in under an hour.

如果只是英格兰,那么您可以自己解决!你需要一个可靠的算法来确定复活节,否则我会说你可以在一个小时内完成。

But do you mean just England, or the UK? Because Scotland has different holidays (Christmas, Hogmanay and St Andrew's Day) and Northern Ireland, Wales and most likely the Isle of Man and the Channel Islands should also be traded differently.

但你的意思只是英格兰,还是英国?因为苏格兰有不同的假期(圣诞节、Hogmanay 和圣安德鲁节),北爱尔兰、威尔士以及最有可能的马恩岛和海峡群岛也应该以不同的方式进行交易。

As noted elsewhere, once your scope gets wider then it's even more complex. There are local holidays, half-days, days when banks are open but stock exchanges not, all kinds of horrors.

正如其他地方所指出的,一旦您的范围变得更广,它就会变得更加复杂。有当地假期,半天,银行营业但证券交易所不营业的日子,各种恐怖。

If you really can't manage holidays yourself and don't have users who can be given responsibility, then I'd suggest going back to your "can't run on a public holiday" constraint and looking for ways in which that might be removed...

如果您真的无法自己管理假期并且没有可以承担责任的用户,那么我建议回到您的“不能在公共假期运行”限制并寻找可能的方法删除了...

回答by Luis Melgratti

google calendar public hollydaysMaybe you could retrive your country/region data with google Calendar web service.

google Calendar public hollydays也许您可以使用 google Calendar 网络服务检索您的国家/地区数据。