How to compare date in UiPath

Hi,

I have the xlsx table. One of the columns is date (generally it is the number) in format:

201808
201809
201810
201811
201812
201901
201902
etc.
I would like to choose ony the rows (I use for each rows), where the above date is equal or smaller to previous month (201901). I have problem with date format to compare these two figures.
In result I should get date from 201808 to 201901.
I hope that someone help me.

Hi,

Refer the below workflowCompareDate.zip (13.4 KB)

you have to convert your string 201808 to datetime and similarly for 201901

Datetime.ParseExact(“201808”,“yyyyMM”,system.Globalization.CultureInfo.InvariantCulture).ToString(“yyyy/MM”)

1 Like

Thank you. At the moment this solution does not work. I think that the reason is below Value:

Convert.ToDateTime(Datetime.ParseExact(Now.AddDays(-50).ToString(“yyyyMM”),“yyyyMM”,system.Globalization.CultureInfo.InvariantCulture).ToString(“yyyy/MM/dd”))

Instead “201901” I used: Now.AddDays(-50).ToString(“yyyyMM”) - I have to get 201901 if I start proces eg. 2019-02-23 or 2019-03-10 - it is the reason that I use -50 days.

The error is: String was not recognized as a valid DateTime.mscorlib

Hi,

Please use the below expression.

now.AddMonths(-1).ToString(“yyyyMM”)

The output of above expression is 201901, so you can use this expression directly in TempDate variable and remove the previous expression.

Probably on first assign (DAte1) I have error:
String was not recognized as a valid DateTime.
and I can not solve this problem.

Finally I converted two figures to intiger and compare them:
Convert.ToInt32(row(“Date”)) <= Convert.ToInt32(New Date(Now.Year,Now.Month,Now.Day).AddDays(-50).ToString(“yyyyMM”))

It works.

Thank you for your help.

1 Like