i want to check whether the dates in a file are consecutive.

that is if the dates are 7.10,2011 ,7.11.2011,7.12.2011 it should return true
and if they are 7.10.2011,7.12.2011 it should return false.

dates are in which file ,is it in a database ?

You can store the dates into an array, and compare the values in the array using the for loop.

Assuming the array name is arrDate:

Dim curDate as Date

curDate=arrDate(0)
For i=1 to arrDate.Count - 1
 If arrDate(i) = curDate.AddDays(1) Then
  con = True
  curDate = arrDate(i)
 Else
  con = False
  Exit For
 End If
Next i

If con=True Then
 MsgBox("The dates are consecutive!")
Else
 MsgBox("The dates are NOT consecutive!")
End If

I believe this should do it, although I havent tested it yet.

Hi, try this code bellow, but just make sure the DateTims are do not have hours, minutes or seconds. They onlymust have days, months and years (hours, minutes and seconds must be on zero, like "7.11,2011 0:00:00".

Private Sub Method()
	Dim dates As DateTime() = New DateTime(2) {}
	dates(0) = New DateTime(2011, 7, 10)
	dates(1) = New DateTime(2011, 7, 11)
	dates(2) = New DateTime(2011, 7, 13)

	Dim bCheckDates As Boolean = CheckConsecutiveDates(dates)
	If bCheckDates Then
		MessageBox.Show("Dates are consecutive.")
	Else
		MessageBox.Show("Dates are NOT consecutive.")
	End If
End Sub

Private Function CheckConsecutiveDates(dates As DateTime()) As Boolean
	Dim bChecking As Boolean = True
	For i As Integer = 0 To dates.Lengh - 1
		If i + 1 < dates.Lenght Then
			If dates(0).AddDays(1) <> dates(i + 1) Then
				bChecking = False
				Exit For
			End If
		End If
	Next
	Return bChecking
End Function
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.