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

Need Count Working Day

P: 1
Hi, Guys

I am creating application in ms-access and i am struggling to counting working days when user gives start date and end date. i don't want to count saturday and sunday.
So, anyone can help how can i do it. i would be very appreciate if you provide me coding for that.

Thanks,
Dec 22 '06 #1
Share this Question
Share on Google+
1 Reply


ADezii
Expert 5K+
P: 8,669
Hi, Guys

I am creating application in ms-access and i am struggling to counting working days when user gives start date and end date. i don't want to count saturday and sunday.
So, anyone can help how can i do it. i would be very appreciate if you provide me coding for that.

Thanks,
This should work nicely for a Generic Code Template
Expand|Select|Wrap|Line Numbers
  1. Dim intNoOfDays As Integer, intCounter As Integer
  2. Dim MyDates() As Date, T As Integer, intNoOfWeekdays As Integer
  3. Dim dteStartDate As Date, dteEndDate As Date
  4.  
  5. dteStartDate = #1/1/2007#   'Starting Date
  6. dteEndDate = #1/31/2007#    'Ending Date
  7.  
  8. intNoOfDays = DateDiff("d", dteStartDate, dteEndDate)   'Days between
  9.  
  10. ReDim MyDates(intNoOfDays)
  11.  
  12. MyDates(0) = dteStartDate   '1st Element in the Array
  13.  
  14. For intCounter = 1 To intNoOfDays   'Initialize other Elements
  15.   MyDates(intCounter) = DateAdd("d", intCounter, dteStartDate)  'place Dates into Array
  16. Next intCounter
  17.  
  18. If intNoOfDays > 0 Then
  19.   For T = 0 To UBound(MyDates)  'Loop through Array
  20.     If Weekday(MyDates(T)) > 1 And Weekday(MyDates(T)) < 7 Then     'Weekends would have values of 1 or 7
  21.       intNoOfWeekdays = intNoOfWeekdays + 1
  22.     End If
  23.   Next T
  24. Else
  25. End If
  26.  
  27. MsgBox "The Number of Weekdays is: " & intNoOfWeekdays
Dec 22 '06 #2

Post your reply

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