How do I determine a public holiday in Sql server?

前端 未结 24 1844
慢半拍i
慢半拍i 2020-12-05 14:40

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

相关标签:
24条回答
  • 2020-12-05 15:20

    I find this topic strange. After trying to find and write complicated functions in MS, PHP or in this case SQL language I came to the conclusion that it is a pointless exercise. The code I ended up contain over 2000 characters and takes hours to get right and debug. If you think about it all you have to do is write 7 number indicating the day 1-365 for each holiday and a row for each year for the next 100 years. You only need to load that years or the next years holidays once. So keep table with 7 columns and 100 rows and fill them up with the correct days. You only need to do this once every 100 years and take less than an hour and it is portable.

    0 讨论(0)
  • 2020-12-05 15:21

    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

    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.

    0 讨论(0)
  • 2020-12-05 15:21

    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!

    0 讨论(0)
  • 2020-12-05 15:21

    This algorithm may reduce the amount of manual configuration in countries that observe Christian holidays. Should be trivial to convert to C#:

    http://en.wikipedia.org/wiki/Computus#Anonymous_Gregorian_algorithm

    0 讨论(0)
  • 2020-12-05 15:22

    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.

    0 讨论(0)
  • 2020-12-05 15:22

    Bank Holidays in the UK are mostly computable, but definitely not all computable.

    The UK government provides an API (https://www.gov.uk/bank-holidays.json) which gives you this info.

    0 讨论(0)
提交回复
热议问题