Ehab Ragab Ehab Ragab - 25 days ago 6 Question

how to loop over dates step one month with

how to use for next with dates in VB.Net

I need to say something like this

For dt As Date = (someDate) to Today().Date step 1 Month

' do something


Answer Source

Try bellow code (using Do While...Loop) :

Label1.Text = ""
Dim somedate As Date = CDate("2017-1-16") 'this is Your somedate
Do While somedate <= Today.Date
    'do something, in this case show date in label
    Label1.Text += String.Format("{0:yyyy-MM-dd}", somedate) + vbCrLf
    'after do something increase somedate for one month
    somedate = somedate.AddMonths(1)

It's important You first do something and then increase Your somedate, otherwise, loop will pass Today.Date and will "jump" to next month after Today.Date.