I am trying to compare two dates in a loop and if the current date is less than or equal to the date’s month and year, add it to a list.
Here is how my syntax looks:
currDate = now.Date.toString(“MMM”)+“-”+ now.Date.toString(“yy”)
if(DateTime.ParseExact(currDate, “MM-yy”, Globalization.CultureInfo.InvariantCulture) <= DateTime.ParseExact(dtData.rows(13).item(9).toString, “MM-yy”, Globalization.CultureInfo.InvariantCultureGlobalization.CultureInfo.InvariantCulture))
dtData.rows(13).item(9).toString prints as an example 12/31/2021 00:00:00.
I don’t think you will need to compare months - going by your problem statement - I would assume you would want to add an entry such as currDate being 08-21 if your compare date is 01-22 (since it’s still before the compare date, even though month is less than current month)?
Please disregard this comment if I understood it wrong.
This wasn’t the exact solution, but if definitely helped me get the right answer. I used this information and put it in a variable then compared it to todays date. Shout out to @lukasziebold tor telling me about the Today DateTime variable.