Counting the Number of Working Days
-
Hi I'm creating a C# program to measure differences between dates. Ive figured out how to measure the difference between two dates using DateTime and TimeSpan, but is there any short cut way on how I will be able to measure the time elapsed with just weekdays? (meaning saturday and sunday will no longer be counted when measuring the difference) thanks
-
Hi I'm creating a C# program to measure differences between dates. Ive figured out how to measure the difference between two dates using DateTime and TimeSpan, but is there any short cut way on how I will be able to measure the time elapsed with just weekdays? (meaning saturday and sunday will no longer be counted when measuring the difference) thanks
Sorry, I don't know any shortcut, but it is not such a daunting task, you need only to take special care about the working days of the first and last weeks (that maybe partial) and keep the 5/7 of the remaining... :)
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
-
Sorry, I don't know any shortcut, but it is not such a daunting task, you need only to take special care about the working days of the first and last weeks (that maybe partial) and keep the 5/7 of the remaining... :)
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
-
Hi I'm creating a C# program to measure differences between dates. Ive figured out how to measure the difference between two dates using DateTime and TimeSpan, but is there any short cut way on how I will be able to measure the time elapsed with just weekdays? (meaning saturday and sunday will no longer be counted when measuring the difference) thanks
Well, may I humbly suggest my http://www.codeproject.com/csharp/TimeRanger.asp[^] You could use it to iterate across the dates and count only the weekdays, maybe even check each against some list of holidays you may have.
-
Hi I'm creating a C# program to measure differences between dates. Ive figured out how to measure the difference between two dates using DateTime and TimeSpan, but is there any short cut way on how I will be able to measure the time elapsed with just weekdays? (meaning saturday and sunday will no longer be counted when measuring the difference) thanks
public static int GetWorkingDatesBetween(DtaeTime DateFrom, DateTime DateTo) { if(DateFrom.CompareTo(DateTo) >= 0 ) throw new ArgumentException("Invalid date ranges! DateTo should be greater than DateFrom"); int totalWorkingDaysElapsed = 0; while(DateFrom.CompareTo(DateTo) != 0) { DateFrom = DateFrom.AddDays(1); if(DateFrom.DayOfWeek == DawOfWeek.Saturday || DateFrom.DayOfWeek == DawOfWeek.Sunday) continue; ++totalWorkingDaysElapsed; } retrun totalWorkinDaysElapsed; } Hope this helps...