User Id :    Password :      New Member   Forgot Password  
Finding Saturday,Sunday between date range in C#/ASP.NET
Description Finding Saturday,Sunday between date range in C#/ASP.NET   No. of Views     2880
  Rating     0
Author Jalpesh Vadgama   Posted On     12 Jun 2011
Tags ASP.NET,C#    

Sample Code   Download Code

I know this post will sound basic to some of the people. But yesterday one of my reader asked me this question. So I decided to write this blog post . So lets first create a console application which will find the Saturday,Sunday between two dates just like following.



Once you are ready with Console application. You need to write following code in that to find and print Saturday and Sunday between particular date range.


using System;
namespace DatimeApplication
   class Program
       static void Main(string[] args)
             DateTime startDate=new DateTime(2011,3,1);
             DateTime endDate = DateTime.Now;
             TimeSpan diff = endDate - startDate;
             int days = diff.Days;
             for (var i = 0; i <= days; i++)
                 var testDate = startDate.AddDays(i);
                 switch (testDate.DayOfWeek)
                     case DayOfWeek.Saturday:
                     case DayOfWeek.Sunday:


As you can see in above code I am finding Saturday and Sunday between 1st March 2011 and today. So I have taken two variables called startDate and endDate. After that I have got difference between them and then via for loop I am checking that day of week is Saturday or Sunday then I am printing that. Now lets run the application and lets check browser and Here you can see below output as expected.



So as you can see it is very Easy. You can find any weekday that way. Hope you liked it. Stay tuned for more..



About Author

About Author I am jalpesh vadgama an Microsoft MVP for Visual C# and BrainBench Certified ASP.NET Developer having more then 5 years of experience in .NET Technology.Please feel free to contact me for any queries via posting comments on my blog I will try to reply as early as possible. Please also visit my blog at Jalpesh Vadgama
No Photo
Country India
Company N/A
Home Page

Rate this article

Rating options from poor, fair, good, very good to excelent.  


Posted By Annonymous on 03 Sep 2011 at 05:09 AM
Great stuff, you hlpeed me out so much!
Write your comment here.
Verification Code