2016-02-19 165 views
-2

我怎樣才能得到正確的格式。兩個月之間的月份差異

可以說我有從21.03.2010 日至21.05.2011

我的時間差日期應該返回像這樣

Months/Years 
    3/2010 
    4/2010 
    5/2010 
    ... 
    12/2010 
    1/2011 
    ... 
    5/2011 

回答

0

這應該讓你去:

Private Sub Button50_Click(sender As Object, e As EventArgs) Handles Button50.Click 

    printDateRange(New Date(2010, 3, 21), New Date(2011, 5, 21)) 

End Sub 

Private Sub printDateRange(startDate As Date, endDate As Date) 

    Dim months As Integer = DateDiff(DateInterval.Month, startDate, endDate) 

    For parser As Integer = 0 To months 
     Dim newdate As Date = startDate.AddMonths(parser) 
     Debug.Print(String.Format("{0}/{1}", newdate.Month, newdate.Year)) 
    Next 

End Sub 

你仍然需要添加所有驗證和錯誤處理等。

相關問題