-
Nov 4th, 1999, 04:48 AM
#1
Thread Starter
Junior Member
hi all,
i have a requirement in my project to find the number of weekdays in between any two given dates. can anyone help me with the code for that. it has to go into production within two days. i would greatly appreciate any help
thanks
Dev
-
Nov 4th, 1999, 05:02 AM
#2
Fanatic Member
What do you mean by the number of weekdays. If you mean just the number of Days You could use DateDiff Function.
------------------
Visual Basic Programmer
-----------------
PolComSoft
You will hear a lot about it.
-
Nov 4th, 1999, 05:08 AM
#3
Thread Starter
Junior Member
DateDiff gives me the total number of days in between the two dates. i want the number of days excluding saturdays and sundays. i should have phrased it as business days or working days probably instead of weekdays
-
Nov 4th, 1999, 06:17 AM
#4
Try this:
Code:
Public Function GetBusinessDaysDiff(pStartDate As Date, pEndDate As Date) As Long
Dim lngDays As Long
Dim lngWeeks As Long
Dim intDifference As Integer
If pStartDate > pEndDate Then
NumberOfBusinessDays = 0
Else
lngDays = DateDiff("d", pStartDate, pEndDate)
lngWeeks = DateDiff("ww", pStartDate, pEndDate)
intDifference = 0
If Weekday(pStartDate) = vbSunday And _
Weekday(pEndDate) <> vbSunday And _
Weekday(pEndDate) <> vbSaturday Then
intDifference = -1
ElseIf Weekday(pStartDate) = vbSunday And _
Weekday(pEndDate) = vbSunday Then
intDifference = 0
ElseIf Weekday(pEndDate) = vbSunday Then
intDifference = 1
End If
If Weekday(pEndDate) <> vbSunday And Weekday(pEndDate) <> vbSaturday Then
intDifference = intDifference + 1
End If
GetBusinessDaysDiff = (lngDays - (lngWeeks * 2)) + intDifference
End If
End Function
Usage: GetBusinessDaysDiff StartDate, EndDate
Example: MsgBox GetBusinessDaysDiff Date, Date + 5
Regards,
------------------
Serge
Software Developer
Serge_Dymkov@vertexinc.com
Access8484@aol.com
ICQ#: 51055819
-
Nov 4th, 1999, 08:16 AM
#5
Thread Starter
Junior Member
Thanks a lot for your code serge. i had to subtract one day from the final result to exclude the start date. thanks anyway
Dev
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|