Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Program to determine number of working days

Status
Not open for further replies.

MJV57

Programmer
Apr 18, 2009
87
0
0
CA
Im looking for an algorithm to use to determine the number of working days remaining in a job. I will feed the start date and the end date but we only work Monday to Friday. Does anyone know how I could do this or have an example.
 
Code:
public int NumberOfWorkDays(DateTime start, DateTime end)
{
   var days = 0;
   var current = start;
   while(current <= end)
   {
       if(current.DayOfWeek == DayOfWeek.Saturday || current.DayOfWeek == DayOfWeek.Sunday) continue;
        days++;
   }
   return days;
}

Jason Meckley
Programmer
Specialty Bakers, Inc.

faq855-7190
faq732-7259
 
ut you will (eventually) need to include provision(S) TO SKIP "LEGAL" holidays. I use a simple table with the holiday name and date, with a lookup to also check them.




MichaelRed


 
Jason how do I tie your code into a database with many jobs with many start and end dates to calculate the days remaining for each job
Thanks
 
if you want to do this work on the database then use tsql. for an optimized approach i would ask in a forum dedicated to that database/tsql dialect.

Jason Meckley
Programmer
Specialty Bakers, Inc.

faq855-7190
faq732-7259
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top