CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Aug 2009
    Posts
    13

    Get all saturdays in a Year using c#

    plz help me to find all saturdays in a year.

  2. #2
    Join Date
    Sep 2008
    Location
    Netherlands
    Posts
    865

    Re: Get all saturdays in a Year using c#

    Code:
             DateTime start = new DateTime(2009, 1, 1);
             DateTime end = new DateTime(2009, 12, 31);
             List<DateTime> saturdays = new List<DateTime>();
             while (start < end) {
                if (start.DayOfWeek == DayOfWeek.Saturday) {
                   saturdays.Add(new DateTime(start.Year, start.Month, start.Day));
                   start = start.AddDays(7);
                }
                else {
                   start = start.AddDays(1);
                }
             }
    I don't know if there is any function that gets all Saturdays in a year, but this code also works

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured