Selecting days

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • melillo
    New Member
    • Feb 2008
    • 1

    Selecting days

    For MS Access database

    Can anyone give me a hand in creating a procedure/query to select the number of Mondays, or Tuesdays, or Wednesdays (or any other day of the week from the seven) occurring within a given period when two dates are inserted? Would appreciate tremendously

    Thanks
  • ADezii
    Recognized Expert Expert
    • Apr 2006
    • 8834

    #2
    Originally posted by melillo
    For MS Access database

    Can anyone give me a hand in creating a procedure/query to select the number of Mondays, or Tuesdays, or Wednesdays (or any other day of the week from the seven) occurring within a given period when two dates are inserted? Would appreciate tremendously

    Thanks
    The following litte code snippet will Print the number of Mondays and Wednesdays between January 1, 2008 and the Current Date. This should point you in the right direction:
    [CODE=vb]
    Dim dteStartDate As Date, dteEndDate As Date
    Dim intNoOfMonAndWe ds As Integer, intDaysDiff As Integer
    Dim intCounter As Integer, dteTestDate As Date

    Const conMONDAY As Integer = 2
    Const conWEDNESDAY As Integer = 4

    dteStartDate = #1/1/2008#
    dteEndDate = Now()
    intDaysDiff = DateDiff("d", dteStartDate, dteEndDate)

    For intCounter = 0 To intDaysDiff
    dteTestDate = DateAdd("d", intCounter, dteStartDate)
    If Weekday(dteTest Date) = conMONDAY Or Weekday(dteTest Date) = conWEDNESDAY Then
    intNoOfMonAndWe ds = intNoOfMonAndWe ds + 1
    End If
    Next

    Debug.Print "The number of Mondays and Wednesdays between " & dteStartDate & " and " & _
    Format$(dteEndD ate, "m/d/yyyy") & " is " & intNoOfMonAndWe ds[/CODE]
    OUTPUT:
    [CODE=text]The number of Mondays and Wednesdays between 1/1/2008 and 2/2/2008 is 9[/CODE]

    Comment

    Working...