I do not read over or edit the content on this blog. There will be spelling errors, grammatical errors, and run-on sentences that make no sense.

Friday, June 30, 2006

C# Code for Business Days After A Certain Date

If you want to find how many business days are after a certain date, look here:


using System;

namespace Utilities
{
class MainClass
{

public DateTime BusinessDaysAfter(DateTime dt, int days)
{

for (int i = 1; i < days; i++)
{
dt = dt.AddDays(1.0);
if (dt.DayOfWeek == DayOfWeek.Saturday || dt.DayOfWeek == DayOfWeek.Sunday)
days++;
}

return dt;
}

public static void Main(string[] args)
{
Utilities.MainClass mc = new Utilities.MainClass();
DateTime dt = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1);
Console.WriteLine(mc.BusinessDaysAfter(dt, 11).ToString());

Console.WriteLine(dt);
}
}
}

0 Comments:

Post a Comment

Links to this post:

Create a Link

<< Home