Sunday, 18 September 2011

Determining the nth occurrence of a day of the week in a month

You may need a formula to determine the date for a particular occurrence of a weekday. For
example, suppose your company payday falls on the second Friday of each month, and you need
to determine the paydays for each month of the year. The following formula makes this type of
calculation:

  =DATE(A1,A2,1)+A3-WEEKDAY(DATE(A1,A2,1))+
  (A4-(A3>=WEEKDAY(DATE(A1,A2,1))))*7

The formula in this section assumes that

      Cell A1 contains a year.

      Cell A2 contains a month.

      Cell A3 contains a day number (1 for Sunday, 2 for Monday, and so on).

      Cell A4 contains the occurrence number (for example, 2 to select the second occurrence
        of the weekday specified in cell A3).

If you use this formula to determine the date of the second Friday in November 2010, it returns
November 12, 2010.

             If the value in cell A4 exceeds the number of the specified day in the month, the for-
             mula returns a date from a subsequent month. For example, if you attempt to deter-
             mine the date of the fifth Friday in November, 2010 (there is no such date), the formula
             returns the first Friday in December.

No comments:

Post a Comment