Results 1 to 3 of 3
  1. #1
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Day Count (A2000 SR1)

    Does any one have a function that will count how many Saturdays their are in a particular month. ??

    Regards
    Dave

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Day Count (A2000 SR1)

    There was a thread a while ago about finding the first or second or ... Sunday or Monday or ... in a particular month. I can't find it quickly now, but I kept a function to do this:

    ' Will return the first, second, third, fourth, fifth or last day of type aDay
    ' in the given year and month.

    ' aYear is the year
    ' aMonth is the month
    ' aDay can be 1=Sunday ... 7=Saturday
    ' aNum can be 1, 2, 3, 4, 5 or 9=Last

    Function DayInMonth(aYear As Long, aMonth As Long, aDay As Long, aNum As Long) As Date
    If aNum = 9 Then
    DayInMonth = DayInMonth(aYear, aMonth + 1, aDay, 1) - 7
    Else
    DayInMonth = DateSerial(aYear, aMonth, _
    7 * aNum + 1 - WeekDay(DateSerial(aYear, aMonth, 1), aDay Mod 7 + 1))
    End If
    End Function

    You can use this to calculate the number of Sundays or Mondays or ... in a particular month:

    ' Will return the number of aDays in a given year and month.
    ' aDay can be 1=Sunday ... 7=Saturday

    Function NumberOfDaysInMonth(aYear As Long, aMonth As Long, aDay As Long) As Long
    NumberOfDaysInMonth = (DayInMonth(aYear, aMonth + 1, aDay, 1) - _
    DayInMonth(aYear, aMonth, aDay, 1)) / 7
    End Function

    To find the number of Saturdays in November 2002, call it like this:

    NumberOfDaysInMonth(2002, 11, 7)
    or
    NumberOfDaysInMonth(2002, 11, vbSaturday)

  3. #3
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Day Count (A2000 SR1)

    Thanks Again
    Regards
    Dave

Posting Permissions

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