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 <= days; i++)
{
var testDate = startDate.AddDays(i);
if (testDate.DayOfWeek != DayOfWeek.Saturday && testDate.DayOfWeek != DayOfWeek.Sunday)
{
j = j + 1;
Console.WriteLine(testDate.ToShortDateString());
}
}
Console.WriteLine(string.Format("Total Days:{0}",j));
Console.ReadLine();
}
}
}
If you see above code, Its very easy to find all days except Saturday and Sunday in a year. I have created two dates with Start date and end date and then I found a difference between those two days. And then in for loop I have checked whether they are weekdays then I have printed a date for that. I have calculated all days except Saturday and Sunday for year 2013. At the end I have printed total days also.
Once you run the code following is a output as expected.
That’s it. Hope you like it. Stay tuned for more…

0 comments:
Post a Comment
Your feedback is very important to me. Please provide your feedback via putting comments.