While condition after certain date

Hi. I want to count back the month and stop at certain date(ex:201801).I set the condition ,but it just execute continuously. Please help set the right condition THX

condition:Convert.ToDateTime(S).ToString<“201801”
assign:S=S.AddMonths(-1)
assign:S=Convert.ToDateTime(S)
messagebox:Convert.ToDateTime(S).ToString(“yyyyMM”)

S:variable type-Datetime Default-Now

Try it with once while loop
and
in while condition your comparing string variables better to use to date variable only like S(DateVariable)<“201801”(date variable)

Hi,

I would recomend using string to compare dates because then you depend on the format of the string (because every character is compared one to one. example: 31.12.2018<01.01.2019 but “31.12.2018”>“01.01.2019”). If you want to do it in a loop with string, then force the format (as you do in the message box)

“I would not recomend”

I modify my condition like

Convert.ToDateTime(S).ToString(“yyyyMM”)>“201801”

then it works! THX

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.