Click here to Skip to main content
15,902,931 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
this is my code which I am going to convert it to Please help me out

public IEnumerable<DateTime> GetAllQuarters(DateTime current, DateTime past)
       var curQ = (int)Math.Ceiling(current.Month / 3.0M);
       var lastQEndDate = new DateTime(current.Year, curQ * 3, 1).AddMonths(-2).AddDays(-1);

           yield return lastQEndDate;
           lastQEndDate = lastQEndDate.AddMonths(-3);
           lastQEndDate = new DateTime(lastQEndDate.Year, lastQEndDate.Month, DateTime.DaysInMonth(lastQEndDate.Year, lastQEndDate.Month));
       } while (lastQEndDate >= past);

What I have tried:

Public Function GetAllQuarters(current As DateTime, past As DateTime) As IEnumerable(Of DateTime)
Dim curQ = CInt(Math.Ceiling(current.Month / 3D))
Dim lastQEndDate = New DateTime(current.Year, curQ * 3, 1).AddMonths(-2).AddDays(-1)

yield Return lastQEndDate
lastQEndDate = lastQEndDate.AddMonths(-3)
lastQEndDate = New DateTime(lastQEndDate.Year, lastQEndDate.Month, DateTime.DaysInMonth(lastQEndDate.Year, lastQEndDate.Month))
Loop While lastQEndDate >= past
End Function
Updated 7-May-17 23:42pm

Check Yield syntax for VB.NET: Yield Statement (Visual Basic)[^]
Yield should be written with capital Y and no return needed...Also check the order of statements (probably Yield should be the last)...
Share this answer
Brian1492 8-Sep-16 17:10pm    
That's not it.
it is just Yield, not Yield Return.

And the Function must be declared

Public Iterator Function GetAllQuarters
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900