All dates format in a given string

Hi,

Curious to know whether can we have a regex to fetch all the forms of dates in a text and then covert all of them in a single format, “dd/mm/YYYY”?

Below are the date formats:

22-MAR-2020
18/03/2020
09/04/20
30.03.2020
20.03.20
4 mars 20
4 Avril 2020

I do have the individual regex for the first 3 formats.

@alpharobot
we do not need regex as datetime Parse exact can be configured to handle multiple formats.

Give me some mins I will search and share the code lines from the past

1 Like

Thanks for the reply and your help!

I need to get the amounts of different form as well, currently extracting them using various regex and then combining. As you mentioned about the date, is there something we can do for amount?

Means to extract all forms of amount from a text?

Need to extract below formats of the amounts

4 450,37
4 022, 18
4,989.12
2.494,23

initial digit can be 1 or 2

41 589,22
14 413, 21
42,093.44
42.477,25

@alpharobot
one by one, and one topic one case, so clear problem-solution pairs can be offered to others who are doing researches

1 Like

@ppr @alpharobot

If(datetime.tryparseexact("dattimeString","formattype",system.globalization.cultureinfo.currentculture,datatimestyle.none,result) )

1 Like

@alpharobot

the formats are configured in a dt:
grafik

so it can be externalized (less formats can be handled in comma seperated string and handled with String .Split…)

following parse is handling many formats in one statement:
DateTime.ParseExact(row(0).ToString.trim, arrFormats, cultureinfo, DateTimeStyles.None)

most of the dates are parsed:
[Column1
22-MAR-2020
18/03/2020
09/04/2020
30/03/2020
20/03/2020
04/03/2020
04/04/2020
]

22-MAR-2020 is not a valid date string and is confusing. So I suggest to you a further RnD:

However it is handled by a try catch and do not block the other dates:

Starter Help here:
Parsing_MultipleFormats_DTConfig.xaml (13.4 KB)

3 Likes

Yeah sorry for this. I’ll take topics it once at a time.

Okay, Thanks a lot @ppr for this information. It’s helpful

I’ll do work on this further.

Hi @alpharobot,

Create an array variable and assign following values into it
{“dd-MM-yyyy”,“dd/MM/yyyy”,“dd/MM/yy”,“dd.MM.yy”,“dd.MM.yyyy”}

DateTime.ParseExact(row(0).ToString, arr_DateFormat, new CultureInfo(“en-US”), DateTimeStyles.None).ToString(“dd-MM-yyyy”)

image

above method to convert date into a single format in comes through in the various format
to use above method you need to add following namespace to uipath otherwise it wont recognize culture and style info

System.Globalization

or you can use the easiest method just

DateTime.Parse(row(0).ToString).ToString(“yyyy-MM-dd”)

Assumption:- row(0).ToString is the value of datatable date value you get from excel

Happy Automation

1 Like

Thanks @SamanGuruge for providing the solution for the conversion task.

But I do not have the list of dates already. I need to extract the dates from a string and that string can contain date in any format mentioned above in my first post. Can you suggest anything for extract all the dates from the string?

Currently I am using different regex for the different type of dates. But can we have more generic regex to extract dates?

you have list of date pattern so that you can include in the array and parse that date pattern and your date value into Exactparse method and convert it into a single format

1 Like

okay Thanks!
I will try this now.

ok let me know if you need anything from my end

1 Like

@SamanGuruge

Sorry, I’m afraid I didn’t get the parse stuff understood correctly.

Can you please have a look at the project attached. The one sample Input file has certain dates in all different formats. I need to extract that and then convert into a standard form.

DateExtract_Asnmnt_18.4.zip (18.4 KB)

Sure i’ll do it wait

1 Like

use this one it working fine for ur all date formats

DateExtract_Asnmnt_18.4 sam.zip (20.8 KB)

3 Likes

Thanks a lot @SamanGuruge :slightly_smiling_face:

that is working fine but just two small doubts

  1. It is extracting “12.12.45” as the original text in another sample file contains “12.45.55.6.5”
    and also extracting “52 EUR 34” as the input contains “124 52 EUR 34 56 EUR”

I will have a try catch and if the error is “Input not a valid date format” than I will delete that item from Match Result. Just want to confirm, any other solution to this?

  1. It is not accepting the months Mai and Mars but not the other ones like, 13 Avril 2020, 9 septembre 2020. can this be added in the match regex of the code?

I have been using this regex extract this type of date : “(0[1-9]|[12][0-9]|3[01])\s(janvier|février|mars|avril|mai|juin|juillet|août|septembre|octobre|novembre|décembre)\s20\d\d\b”

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