Click here to Skip to main content
16,016,770 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
In my vb6 form I have 2 DTPicker. Now I want to count the Friday between this two dates on vb6 form

What I have tried:

I Have try to count exclude Friday as follow. Type mismatch error occurred.

VB
Dim iDay As Long, i As Long, iWeekdays As Long

Date1 = f(DTPicker2.value)
Date2 = f(DTPicker6.value)
' loop through each date and check day
For i = 0 To DateDiff("d", Date1, Date2)
    iDay = Weekday(Date1 + i, vbSaturday)
    If iDay < 6 Then
        ' not Saturday or Sunday
        iWeekdays = iWeekdays + 1
    End If
Next i
Text3.Text = iWeekdays
Posted
Updated 14-Oct-16 10:37am
v2
Comments
Garth J Lancaster 14-Oct-16 7:33am    
what is the iDay value for Friday .. dont you just need

if iDay == (Friday Value)
iFridays += 1;
End If

???
Maciej Los 14-Oct-16 16:32pm    
OP wants to exclude fridays ;)
Garth J Lancaster 15-Oct-16 0:01am    
Sure - I get what you've done - but he has 'count Friday' x 2 and 'count exclude Friday' :-(

1 solution

Your logic is wrong!

VB
If iDay < 6 Then


Check this:
VB
If iDay <> 6 Then


For further details, please see: Weekday Function (Visual Basic)[^]

I'd change your code to:
VB
For aDay = Date1 To Date2
    If WeekDay(aDay) <> 6 Then
        iDays = iDays + 1
    End If
Next aDay

Where aDay variable is type of Date and iDays is type of Integer.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900