.NET Fiddle

CSharp · Console

/Program.cs

using System;
					
public class Program
{
	public static void Main()
	{
		

       int totalWorkingDaysInMonth = GetWorkingDays(DateTime.Now.AddDays(-31),DateTime.Now);
                            
		
		Console.WriteLine(totalWorkingDaysInMonth);

	}
	
	public static 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)); 
		} 
		else 
		{ 
		return (((tSpan.Days / 7) * 5) + Math.Min((dowEnd + 6) - Math.Min(dowStart, 6), 5)); 
		} 
    } 
}
;