# While condition after certain date

**URL:** <https://forum.uipath.com/t/while-condition-after-certain-date/112619>\
**Category:** Help\
**Tags:** system, activities\
**Created:** [April 26, 2019, 9:08am UTC](https://forum.uipath.com/t/while-condition-after-certain-date/112619 "2019-04-26T09:08:44Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![zxc456183](https://avatars.discourse-cdn.com/v4/letter/z/58f4c7/32.png) [@zxc456183](https://forum.uipath.com/u/zxc456183)\
**Post date:** [April 26, 2019, 9:08am UTC](https://forum.uipath.com/t/while-condition-after-certain-date/112619/1 "2019-04-26T09:08:44Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![shyamm](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/shyamm/32/51759_2.png) [@shyamm](https://forum.uipath.com/u/shyamm)\
**Post date:** [April 26, 2019, 9:15am UTC](https://forum.uipath.com/t/while-condition-after-certain-date/112619/2 "2019-04-26T09:15:27Z")

</div>

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)

---

<div class="post-metadata">

**Author:** ![RockSolid](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/rocksolid/32/257522_2.png) [@RockSolid](https://forum.uipath.com/u/RockSolid)\
**Post date:** [April 26, 2019, 11:29am UTC](https://forum.uipath.com/t/while-condition-after-certain-date/112619/3 "2019-04-26T11:29:10Z")

</div>

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)

---

<div class="post-metadata">

**Author:** ![RockSolid](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/rocksolid/32/257522_2.png) [@RockSolid](https://forum.uipath.com/u/RockSolid)\
**Post date:** [April 26, 2019, 11:29am UTC](https://forum.uipath.com/t/while-condition-after-certain-date/112619/4 "2019-04-26T11:29:28Z")

</div>

“I would not recomend”

---

<div class="post-metadata">

**Author:** ![zxc456183](https://avatars.discourse-cdn.com/v4/letter/z/58f4c7/32.png) [@zxc456183](https://forum.uipath.com/u/zxc456183)\
**Post date:** [April 29, 2019, 12:48am UTC](https://forum.uipath.com/t/while-condition-after-certain-date/112619/5 "2019-04-29T00:48:13Z")

</div>

I modify my condition like

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

then it works! THX

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/system/32/182466_2.png) [@system](https://forum.uipath.com/u/system)\
**Post date:** [May 2, 2019, 12:48am UTC](https://forum.uipath.com/t/while-condition-after-certain-date/112619/6 "2019-05-02T00:48:19Z")

</div>

Closed on May 2, 2019, 12:48am UTC

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