code: def pickNthWeekday(year, month, dayofweek, hour, minute, whichweek):
      
      first = datetime.datetime(year=year, month=month, hour=hour, minute=minute,
                                day=1)
      weekdayone = first.replace(day=((dayofweek - first.isoweekday()) % 7 + 1))
      for n in xrange(whichweek - 1, -1, -1):
          dt = weekdayone + n * WEEKS
          if dt.month == month:
              return dt
docs: dayofweek == 0 means Sunday, whichweek > 4 means last instance