Organizations always try to manage their employees performance to make do of them which will lead to increased revenue and customer trustworthy.
I am working now on such application called Time Capturing System (TCS). TCS allows employees to charge their time against a project from their profiles.
TCS ends up with some complicated reports such as Cost Recovery Tool (CRT) and some Utilization Reports. Therefore, I need to compute the working hours for every month.
I wrote a method named MonthWorkingHours. The method assumes that Weekend days are Friday and Saturday and Working Hours per day is 8 hours, So working hours per month = Business days * Working hours per day.
MonthWorkingHours takes year and month as parameters and returns month working hours as Int.
Note that you might need to pass working hours per day and weekend days to the method which I ignored here for the sake of simplicity.
public int MonthWorkingHours(int year, int month) { // days in month int monthDays = DateTime.DaysInMonth(year,month); //month end date DateTime endDate = new DateTime(year,month,monthDays); //current day by default is the start date DateTime currentDay = new DateTime(year, month, 1); int workingDays = 0; //check if the current day is weekend day while (currentDay <= endDate) { if (currentDay.DayOfWeek != DayOfWeek.Friday && currentDay.DayOfWeek != DayOfWeek.Saturday) { workingDays++; } currentDay = currentDay.AddDays(1); } return workingDays * 8; // 8 is working hours per day }
This is not the complete story, you might need to exclude Public Holidays from the business days and the like.
Happy Weekend…
One thought on “Working Hours Monthly”