How to find days in year except Saturday and Sunday in C#

  • Home
  • Blog
  • How to find days in year except Saturday and Sunday in C#

Before 2 years I have written a blog post to find Saturday and Sunday in given date range.  It has gain a lot of popularity and on that blog post one user ask about how we can find days in year except Saturday and Sunday in C#. This post is a in reply for that. Following is a code for that.

using System;

namespace DatimeApplication
{
    class Program
    {
        static void Main(string[] args)
        {
            DateTime startDate = new DateTime(2013, 1, 1);
            DateTime endDate = new DateTime(2013, 12, 31);

            TimeSpan diff = endDate - startDate;
            int days = diff.Days;
            int j=0;
            for (var i = 0; i