Hello,
For a project I’m extracting the date from a table in format DD/MM (year is not provided) and I’d like to filter for results older than 2 months compared to today’s date.
Any ideas how to best handle this issue?
I’m a UIPath rookie, any help would be much appreciated.
1 Like
@LPlissart
Welcome to UiPATH Community
- Once after getting the date from the table named for example like out_dt of type datatable use a for each row loop to iterate through each row in the table
- In for each row loop pass the input as out_dt and use a if condition inside the for each row loop
- with if condition use a condition like this
Datetime.Parseexact(row(yourdatecolumnname).ToString,“dd/MM”,
System.Globalization.CultureInfo.InvariantCulture).ToString(“dd/MM/yyyy”) < Now.AddMonths(-2).ToString
This would work buddy @LPlissart
if you are facing any error while parsing, kindly change the format mentioned above exactly as same as yourdatecolumnname-string…they both should match with each other
Cheers @LPlissart
kindly try this and let know whether this works or not
we can easily sort this out
1 Like
Thanks for the help @Palaniyappan, I tried to make it work, unfortunately I get an error message:
At first I thought it was due to the fact that the dates I extract are under a different format when they’re less than a week old
But in the end I’m not quite sure this is the issue. I believe I used the correct date format, here’s my if condition:
1 Like
your last one is good …but we have strings like 6 days ago…
For that add another condition like if the extracted value is not 6 days ago, then go for the above parsing else take that 6 days ago as a string… while that was the error as we try to convert that string as a datetime which is actually not a datetime…
Try this and let know @LPlissart
Cheers
Thanks again @Palaniyappan but since I can have this exception with other situations (6 days ago but also: yesterday, 5 days ago, etc.) how can I englobe all these situations?
I was thinking of adding an if condition to check if the “Date” is of type datetime but I’m not sure how to write this expression. I tried this but it’s not correct:
Hello again, I changed my datatable to have the same date format for the whole column but I’m still getting the same error msg:
Here’s the datatable:
The error msg:
And the if condition:
I believe it should work but somehow it still doesn’t…
1 Like
you can write condition like this @LPlissart
Not row(“Date”).ToString.Contains(“ago”)
rather to check with the date , where the above conditions validate we have a row of value with string ago in it
you need to change the format like this as the date format got changed @LPlissart
Datetime.Parseexact(row(“Date”).ToString, “dd-MMMM” ,
System.Globalization.CultureInfo.InvariantCulture).ToString(“dd/MM/yyyy”) < Now.AddMonths(-2).ToString
Try this and let knw @LPlissart
This would work for sure
Cheers
alright just before this conversion of string to datetime
use a writeline activity to check how the value of date is getting printed from excel and check buddy
lets see that and based on tht we can put the string date format, that would be very easy from there on AS WE ARE ALMOST DONE
Cheers @LPlissart
@LPlissart
Datetime.Parseexact(row(“Date”).ToString.Substring(0,10).Trim, “dd-MM-yyyy” ,
System.Globalization.CultureInfo.InvariantCulture).ToString(“dd/MM/yyyy”) < Now.AddMonths(-2).ToString
Got this output from the write line:
So I adapted the expression to:
Datetime.Parseexact(row(“Date”).ToString.Substring(0,10).Trim,“/dd/MM/yyyy HH:mm:ss”,
System.Globalization.CultureInfo.InvariantCulture).ToString(“dd/MM/yyyy”) < Now.AddMonths(-2).ToString
But still got the error msg buddy.
Remove that slash before dd @LPlissart
and try this
Datetime.Parseexact(row(“Date”).ToString,"dd/MM/yyyy hh:mm:ss ",
System.Globalization.CultureInfo.InvariantCulture).ToString(“dd/MM/yyyy”) < Now.AddMonths(-2).ToString(“dd/MM/yyyy”)
Done but I still get the error msg
1 Like
aaaaaaaah sorry man
alright relax
it was first month and then only date but we used date and month thats why
try this buddy @LPlissart
sorry for the inconvenience
Datetime.Parseexact(row(“Date”).ToString,"MM/dd/yyyy hh:mm:ss ",
System.Globalization.CultureInfo.InvariantCulture).ToString(“dd/MM/yyyy”) < Now.AddMonths(-2).ToString(“dd/MM/yyyy”)
No inconvenience, I’m very grateful for your help!
Unfortunately it still doesn’t seem to work
1 Like
@LPlissart
Still any date conversion issue or you didn’t get any value out of it
Cheers
If any date conversion
Datetime.Parseexact(row(“Date”).ToString,"MM/dd/yyyy HH:mm:ss ",
System.Globalization.CultureInfo.InvariantCulture) < Now.AddMonths(-2) or Datetime.Parseexact(row(“Date”).ToString,"MM/dd/yyyy hh:mm:ss ",
System.Globalization.CultureInfo.InvariantCulture) < Now.AddMonths(-2)
@Palaniyappan
I tried these 2 expressions, unfortunately it didn’t solve my issue. But I realized the date format wasn’t a big issue anymore so I played around with the filter wizard and this seems to work:
Thanks again for all the help!
1 Like