How to compare multiple dates at once

Hello guys,

There is a website of which I want to get data from and paste it into an Excel sheet.
I choose “Global (English)” for "Country, then “Services”, than “Tax” and then “View All Tax Documents”.
I made an input box in which a user can enter a date. The idea is that the robot stops when the robot is at the date the user entered.

This works, but there is a problem: there are days, such as the 29th of July, on which no documents were uploaded. So if I type 29-07-2017 (I already made the robot convert Jul to 07), the robot will run virtually endlessly.

I compared this:
“[0-”+d1+“][0-”+d2+“]-”+Rawmaand+“-”+RawJaar

to the date the user entered.
RawMaand is just the month the user entered, RawJaar is the year, both are in String format.

d1 is the first digit of the day the user entered, d2 is the second digit.

So when a number lower than d1d2 is found, together with the same month and same year that the user entered in the input box, a variable called “DatumBereikt” (which is Dutch for “DateReached”) will be changed from “false” to “true”, which causes the robot to stop (Boulean)

However, I think UiPath is not recognizing the RegEx I used in a proper way, I have the feeling that it literally searched for [0-“digit entered”][0-“digit entered”]-month-year, rather than “everything lower than”.

Does anyone know what I did wrong, and what I can do to solve the problem?

Thank you in advance!

I’m not sure this is going to work. Have you extracted your data into a datatable? If so there are more options available to you such as dt.Select statements, creating a data view and looping through the table and using an if statement…

1 Like

Hi,

I felt like I should clarify that, indeed, a regex like [0-1][0-3]-8-2017 reads like “one digit matching zero or one, one digit matching zero through three” followed by a fixed part. The strings matching the first part would be 00, 01, 02, 03, 10, 11, 12, 13, which looks like numbers in base 4; this is probably not what you’re after. In other words, the regex engine only “sees” individual characters and numbers are just sequences of digit characters as far as it’s concerned. You can use regexes to find/extract a particular number in a string but not to perform numerical comparisons.

Therefore, it’s probably best to follow @richarddenton’s advice and perform the filtering operation on the DataTable. Also, it’s much more convenient to work with dates as DateTime variables, which can be compared to each other and probably also used, as someDate.ToShortDateString, in DataTable Select queries.

Hello,

From my part, if would handle this in a different way.
Rather than checking if the EY date is equal to what you search, i would look if it’s lower than the search date.

In order to perform that you would need to convert both values as System.DateTime. To do it from a string you can use the parsing methods from DateTime.

example:

*Validate user input to match expected format

dtmIInput = Datetime.ParseExact(strUserInput,“dd-MM-yyyy”,Globalization.CultureInfo.InvariantCulture)
dtmEY= Datetime.ParseExact(strEYdate,“dd MMM, yyyy”,Globalization.CultureInfo.InvariantCulture)

dd-MMM, yyyy is the Format displayed by the EY website for me but it could be different for you.

If dtm dtmIInput < dtmEY then Stop else Continue

This example would be using ParseExact but you might also want to consider DateTime.Parse or Even Datetime.TryParse, TryParseExact

Good luck

Cheers

1 Like

Thank you all for your comments. I will try any of your ideas. There is no datatable in UiPath at the moment, but it is possible to get it from the Excel sheet it is writing and than do something with that. When I am done trying your solutions, I will tell what happened and whether I managed to get it working.

It is cool that you replied so quickly and many thanks!

Florent going for an option that’s not regex!! Not like you :slight_smile:

2 Likes

I think it is a good option, but I can’t get it working ):
It says: Assign : String was not recognized as a valid DateTime.

The format it cannot recognize is dd-MM-YYYY, since I converted both dates to the same format.

I have two assign activities:

dtmEY
Datetime.ParseExact(OmzettenDatum,“dd-MM-yyyy”,Globalization.CultureInfo.InvariantCulture)

OmzettenDatum means “conversed date” which is in the dd-MM-YYYY format
dtmEY is a DateTime variable, OmzettenDatum is a String

dtmInvoer
Datetime.ParseExact(DatumInvoer,“dd-MM-yyyy”,Globalization.CultureInfo.InvariantCulture)
dtmInvoer is a DateTime variable, DatumInvoer is the user input as a string in the dd-MM-YYYY format.

I attached the project, you can find this part in the Check Datum / Tax Alerts sequence in the flowchart.
Main(Autosaved)(Autosaved).xaml (71.2 KB)

Hi @trabart

I made a workflow here extracting the first page data until the selected date included (input box a start).
you would need to extend it to handle more page but I don’t think this will be an issue.

Hope it will help you, let me know if you have any question

EY_CheckDatum.xaml (24.0 KB)

Cheers

1 Like