2011-01-26 52 views
-2

我在VB.NET應用程序中有2個DateTime值。datetime range vb.net for loop

昏暗的startDate爲DATETIME 昏暗的結束日期爲DATETIME

現在我想爲的startDate和結束日期之間一樣,每天一個循環:

對於每一天都當作整數??????? ???

Next

有人有想法嗎?

+1

如果你發現自己的解決問題的辦法,那麼請張貼作爲一個答案,並接受它作爲正確的答案(你不會收到任何代表,因此這很好)。這樣其他人也可以從中受益。 – 2011-01-26 08:38:03

回答

2

C#

for(DateTime CurrentDate = StartDate; 
    CurrentDate < EndDate; 
    CurrentDate = CurrentDate.AddDays(1)) 
{ 
} 

VB.NET

Dim CurrentDate As DateTime = StartDate 
While CurrentDate < EndDate 
    CurrentDate = CurrentDate.AddDays(1) 
End While 
+0

糟糕...我自動在C#中回答。 – BeemerGuy 2011-01-26 08:20:50

+0

感謝這個工程,但我有一個更好的方法,爲尋找解決方案的人,看看TimeSpan對象。無論如何感謝 – Vincent 2011-01-26 08:27:51

1
Dim currentDate As Date = startDate 
While currentDate <= endDate 
    'do something with this date...' 
    currentDate = currentDate.AddDays(1) 
End While