Discussion Locked

in VB6 how many days between 2 date?

0 helpful
7 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.
I want to know for example how many Sunday days between two days

7 replies

by khalid

i don't mean i want to know how many days but i mean i want to know how many sunday or monday between two date

by seagull data services

Sorry, didn't read the question properly.
Use the weekday function to determine the day of the week, add the appropriate number of days to get to the first Sunday. Your answer should be int(dtDate2-dtFirstSunday).
Haven't actually tried it out but it should work. Also, you may not want to count the original first date if it is a Sunday.

by rsv

Dim d1 As Date
Dim d2 As Date
Dim dd As String
Dim c As Integer
Dim i As Integer
d1 = Date
d2 = "06/15/2001" 'mm/dd/yy
dd = DateDiff("d", d2, d1, vbSunday, vbUseSystem)
For i = 0 To Int(dd) - 1
dd = Weekday(DateAdd("d", i, d2), vbSunday)
If dd = 1 Then
c = c + 1
End If
Next
MsgBox "Total Sundays between " & d2 & " and " & d1 & " are " & c

Hope this helps you.
GOOD LUCK...:)

This discussion is closed to new replies.