Datediff - week days only

  • Thread starter Thread starter Dennis
  • Start date Start date
D

Dennis

Does anyone know how to count the number of weekdays between two dates?
 
Here's a "brute-force" function (found in another newsgroup) for doing what
you seek:

Public Function NumberOfWeekDays(datStart As Date, datEnd As Date) As Long
Dim lngNumber As Long, lngTotalDays As Long, lngCount As Long
lngTotalDays = datEnd - datStart
lngNumber = 0
For lngCount = 1 To lngTotalDays
If DatePart("w", datStart + lngCount, vbMonday) < 6 Then lngNumber =
lngNumber + 1
Next lngCount
NumberOfWeekDays = lngNumber
End Function
 
the easy way is :

temp = datediff("w", Date1, Date2)

the "w" argument means weekdays. Look at the help for DateDiff, its
very useful.
 
Oops... I doubt it. Have you tested this?
DateDiff("w",#12/31/2003#,Date()) = 2
I don't think that is what the OP was looking for.
 
OOps. you're right. Didn't test this one. First time and it bit me.
So Sorry.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Back
Top