.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month

Home >> Forum >> ASP.Net >> Post New QuestionBookmark and Share Subscribe to Forum

How to get business or working day in a month in c#

Posted By: Ramesh     Posted Date: February 13, 2009    Points:2   Category :ASP.Net
How to Get business day or working day in a month in C#. This is my requirement means i have remove Saturday and Sunday in a given month and get the number of working day fall under that given month.

Hope i am clear with my requirement.

I am using ASP.Net and c# as and language.

Any help would be appreciated


Author: Amit Mehra             
Posted Date: February 17, 2009     Points: 5   

Use this C# code to get the number of working days in within given days.

private int GetWorkingDays(DateTime dtmStart, DateTime dtmEnd)
// This function includes the start and end date if it falls on a weekday
int dowStart = ((int)dtmStart.DayOfWeek == 0 ? 7 : (int)dtmStart.DayOfWeek);
int dowEnd = ((int)dtmEnd.DayOfWeek == 0 ? 7 : (int)dtmEnd.DayOfWeek);
TimeSpan tSpan = dtmEnd - dtmStart;
if (dowStart <= dowEnd)
return (((tSpan.Days / 7) * 5) + Math.Max((Math.Min((dowEnd + 1), 6) - dowStart), 0));
return (((tSpan.Days / 7) * 5) + Math.Min((dowEnd + 6) - Math.Min(dowStart, 6), 5));

Please "Mark As Answer " if this post help you.

Post Reply

You must Sign In To post reply
Find more Forum Questions on C#, ASP.Net, Vb.Net, SQL Server and more Here
Quick Links For Forum Categories:
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  OOPs  SilverlightIISJQuery

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend