Calculating the Weekend Days(Saturaday,Sunday)

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Manikgisl
    New Member
    • Oct 2008
    • 37

    Calculating the Weekend Days(Saturaday,Sunday)

    HI,

    I have two different dates

    26-12-2008 to 26-01-2009
    these are the two dates ..

    i want calculate number of saturday and sundays in between two dates



    Pls help me

    With Regards,

    Mani
  • tlhintoq
    Recognized Expert Specialist
    • Mar 2008
    • 3532

    #2
    What have you tried so far?

    Comment

    • tlhintoq
      Recognized Expert Specialist
      • Mar 2008
      • 3532

      #3
      Have a counter for Saturday and another counter for Sunday.
      Loop through all the days and if that day is one or the other, add to the appropriate counter.

      Code:
                      DateTime DateInQuestion = DateTime.Now;
                      if (DateInQuestion.DayOfWeek == DayOfWeek.Saturday)
                      {
                          // Increment Saturday counter
                      }
                      else if (DateInQuestion.DayOfWeek == DayOfWeek.Sunday)
                     {
                         // Increment Sunday counter
                      }

      Comment

      • vekipeki
        Recognized Expert New Member
        • Nov 2007
        • 229

        #4
        Maybe you could get it from the total number of days between those two dates?

        Code:
        double numberOfDaysElapsed = (date2 - date1).TotalDays;
        Note that you need to take into account which week days your dates actually are (e.g. Monday to Wednesday is not the same as Friday to Sunday).

        Comment

        • tlhintoq
          Recognized Expert Specialist
          • Mar 2008
          • 3532

          #5
          Exactly. There are several ways to do this. Counters looping through, or formula based on the days of the week for the starting date etc. Which is why I asked what the OP had tried so far... If he actually tried anything at all before asking for help.

          Comment

          Working...