Business Days To - CSharp System

CSharp examples for System:DateTime Day

Description

Business Days To

Demo Code


using System;//from  ww w .jav  a 2 s . c om

public class Main{
        public static int BusinessDaysTo(this DateTime fromDate, DateTime toDate)
        {
            var ret = -1;
            var dt = fromDate;
            while (dt < toDate)
            {
                if (dt.IsBusinessDay())
                {
                    ret++;
                }

                dt = dt.AddDays(1);
            }
            return ret;
        }
        public static bool IsBusinessDay(this DateTime date)
        {
            return
                date.DayOfWeek != DayOfWeek.Saturday &&
                date.DayOfWeek != DayOfWeek.Sunday;
        }
}

Related Tutorials