By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,493 Members | 1,351 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,493 IT Pros & Developers. It's quick & easy.

Selecting days

P: 1
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
Feb 2 '08 #1
Share this Question
Share on Google+
1 Reply


ADezii
Expert 5K+
P: 8,597
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:
Expand|Select|Wrap|Line Numbers
  1. Dim dteStartDate As Date, dteEndDate As Date
  2. Dim intNoOfMonAndWeds As Integer, intDaysDiff As Integer
  3. Dim intCounter As Integer, dteTestDate As Date
  4.  
  5. Const conMONDAY As Integer = 2
  6. Const conWEDNESDAY As Integer = 4
  7.  
  8. dteStartDate = #1/1/2008#
  9. dteEndDate = Now()
  10. intDaysDiff = DateDiff("d", dteStartDate, dteEndDate)
  11.  
  12. For intCounter = 0 To intDaysDiff
  13.   dteTestDate = DateAdd("d", intCounter, dteStartDate)
  14.     If Weekday(dteTestDate) = conMONDAY Or Weekday(dteTestDate) = conWEDNESDAY Then
  15.       intNoOfMonAndWeds = intNoOfMonAndWeds + 1
  16.     End If
  17. Next
  18.  
  19. Debug.Print "The number of Mondays and Wednesdays between " & dteStartDate & " and " & _
  20.              Format$(dteEndDate, "m/d/yyyy") & " is " & intNoOfMonAndWeds
OUTPUT:
Expand|Select|Wrap|Line Numbers
  1. The number of Mondays and Wednesdays between 1/1/2008 and 2/2/2008 is 9
Feb 2 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.