Results 1 to 4 of 4
  1. #1
    salisbut is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Jun 2010
    Posts
    52

    Find # of Sundays in a month


    Is there any function already made that finds the # of a certain weekday in a month? For example, if I wanted to find the number of sundays for August 2010 it would return five. I have searched the web but have not found anything yet.

  2. #2
    trb5016 is offline Advanced Beginner
    Windows Vista Access 2007
    Join Date
    Dec 2009
    Location
    Pennsylvania
    Posts
    71
    There's probably a more efficient way of doing this, but this works *shrug*

    Public Function NumSundays(MonthName As String, intYear As Integer) As Integer

    Dim FirstofMonth, LastDayofMonth As Date
    Dim dDay As Date
    Dim DayCount As Integer

    'Converts Month/Year to date (will return first of month)
    FirstofMonth = (CDate(MonthName & " " & intYear))
    LastDayofMonth = DateSerial(Year(FirstofMonth), Month(FirstofMonth) + 1, 0)

    DayCount = 0

    'Loops through days of month
    For dDay = FirstofMonth To LastDayofMonth
    If WeekdayName(Weekday(dDay)) = "Sunday" Then
    DayCount = DayCount + 1
    End If
    Next

    NumSundays = DayCount

    End Function
    Last edited by trb5016; 08-18-2010 at 12:16 PM. Reason: or not

  3. #3
    jzwp11 is offline VIP
    Windows 7 Access 2007
    Join Date
    Jun 2010
    Location
    Dayton, OH
    Posts
    2,901
    With the weekday() function, you can determine on which day of the week a date falls. I would guess that you could create a custom function that loops through the days of a month (you provide the month and the year) and counts the number of Sundays. To make it a little more versatile, you can also supply the day of the week for which you want the count (not just Sunday).

    I went ahead and created a simple form that utilizes code in the on click event of the button that does the calculation. The database is attached.

  4. #4
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 Access 2007
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Lots of help on this one. Here's another: http://www.mvps.org/access/datetime/date0011.htm

Please reply to this thread with any new information or opinions.

Similar Threads

  1. How to group by month
    By okrobie in forum Queries
    Replies: 4
    Last Post: 06-09-2011, 04:41 AM
  2. First Weds of Month...
    By dweekley in forum Queries
    Replies: 5
    Last Post: 05-17-2010, 12:04 AM
  3. month function..
    By thewabit in forum Programming
    Replies: 13
    Last Post: 04-19-2010, 10:01 PM
  4. by year by month
    By nkuebelbeck in forum Reports
    Replies: 21
    Last Post: 03-24-2010, 01:53 PM
  5. SQL Query by day to end of month
    By tcasey in forum Queries
    Replies: 0
    Last Post: 10-07-2008, 09:55 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums