Following function  will  get a list of months  with days remaining in those months  when start date and end dates are provided


Shared Function GetMonthsList(StartDate As Date, EndDate As Date) As ArrayList

Try

Dim dt As Date = StartDate
Dim edt As Date = EndDate

Dim ar As New ArrayList
Dim str As New StringBuilder

While dt < edt

str.Append(dt.Date.ToString("MMMM yyyy"))
str.Append(",")
Dim dt2 As Date = dt.AddMonths(1)

If dt2 > edt Then
Dim minusdays As Integer = DateDiff(DateInterval.Day, dt, edt)
str.Append(minusdays + 1)
ar.Add(str.ToString)
Exit While
End If

Dim remainingdays As Integer = System.DateTime.DaysInMonth(dt.Year, dt.Month) - dt.Day
str.Append(remainingdays + 1)

ar.Add(str.ToString)
dt = dt.AddDays(remainingdays + 1)
str.Clear()
End While

Return ar

Catch ex As Exception
Throw ex
End Try
End Function

Use can use this functions as


GetMonthsList(Date.Parse("1/4/2012"),Date.Parse("4/30/2012"))

this will output

January 2012,28
February 2012,29
March 2012,31
April 2012,30