How To Print All Saturdays of Current Month In C#

How to Print all Saturdays of Current Month in C#


Please Subscribe Youtube| Like Facebook | Follow Twitter

In this tip we will write a code that will print all Saturdays of Current Month.

var firstDayOfMonth = new DateTime(DateTime.Today.Year, DateTime.Today.Month, 1);
var lastDayOfMonth = firstDayOfMonth.AddMonths(1).AddDays(-1);

while (firstDayOfMonth <= lastDayOfMonth)
{
        //You can print any day just by Giving name of a day here
 	if (firstDayOfMonth.DayOfWeek.ToString() == "Saturday")
        {

             Console.WriteLine(firstDayOfMonth.ToString("yyyy-MM-dd"));

        }
           
              firstDayOfMonth = firstDayOfMonth.AddDays(1);
}
Please Subscribe Youtube| Like Facebook | Follow Twitter


Leave a Reply

Your email address will not be published. Required fields are marked *