I want to calculate the next business date for a given month and date.
For example:
I'll give the month 'January' and date '1'. I want to get the result of date is `Ddecember' and '31' (in the following year) . Please help me to calculate it.
I want to calculate the next business date for a given month and date.
For example:
I'll give the month 'January' and date '1'. I want to get the result of date is `Ddecember' and '31' (in the following year) . Please help me to calculate it.
Try:
var startDate = ...;
while (startDate.DayOfWeek == DayOfWeek.Saturday || startDate.DayOfWeek == DayOfWeek.Sunday)
startDate = startDate.AddDays(1);
Next year's previous business day:
var startDate = ...;
startDate = startDate.AddYears(1);
while (startDate.DayOfWeek == DayOfWeek.Saturday || startDate.DayOfWeek == DayOfWeek.Sunday)
startDate = startDate.AddDays(-1);
What constitutes a business day? If anything bar Sat/Sunday you can use an extension method such as Calculate the number of business days between two dates?
However in most countries you would also ignore bank holidays which usually means that you want to have a table/list of those as well and ensure you ignore them. So you can have a method to evaluate both of these conditions.
Think about your rules, including going back to the previous business day rather than forward to the next applicable business day. Once you have the set of rules you can define functions to evaluate candidate business days plus navigating between days to find the right result.