Calculate public and federal holidays for a given year with native and English translations. Supports countries and subdivisions, covering over 100 countries worldwide.
$ dotnet add package Nager.DateNager.Date is a comprehensive .NET library for querying public and federal holidays, supporting over 110 countries worldwide. It provides native and English translations and supports country subdivisions (federal states) according to ISO 3166-2 standards.
You can see the full list of supported countries here
HolidaySystem.LicenseKey = "TheLicenseKey";
var licenseKey = "TheLicenseKey";
var licenseInfo = Nager.Date.License.LicenseHelper.CheckLicenseKey(licenseKey);
if (licenseInfo is null)
{
//license key invalid
return;
}
if (licenseInfo.ValidUntil < DateTime.Today)
{
//license key expired
return;
}
var holidays = HolidaySystem.GetHolidays(2024, "DE");
foreach (var holiday in holidays)
{
Console.WriteLine($"{holiday.Date:yyyy-MM-dd} - {holiday.EnglishName}");
//holiday...
//holiday.Date -> The date
//holiday.ObservedDate -> The date on which the holiday is observed
//holiday.LocalName -> The local name
//holiday.EnglishName -> The english name
//holiday.NationalHoliday -> Is this holiday in every county (federal state)
//holiday.SubdivisionCodes -> Is the holiday only valid for a special county ISO-3166-2 - Federal states
//holiday.HolidayTypes -> Public, Bank, School, Authorities, Optional, Observance
}
var startDate = new DateTime(2016, 5, 1);
var endDate = new DateTime(2024, 5, 31);
var holidays = HolidaySystem.GetHolidays(startDate, endDate, CountryCode.DE);
foreach (var holiday in holidays)
{
//holiday...
}
var date = new DateTime(2024, 1, 1);
if (HolidaySystem.IsPublicHoliday(date, CountryCode.DE))
{
Console.WriteLine("This date is a public holiday.");
}
var date = new DateTime(2024, 1, 1);
if (WeekendSystem.IsWeekend(date, CountryCode.DE))
{
Console.WriteLine("The date falls on a weekend.");
}