How we can extract only date from string "Exchange Rate Notification No. 76/2023-Cus (NT) dated 19.10.2023-reg [Effective from 20th October, 2023]"

I have a string and want to extract only “20th October, 2023” this date from a string,

and also convert the date into 20.10.2023 format and save into one variable (Str_Effective Date )

@Ajinya_jorwekar

InputDateTimeString =System.Text.RegularExpressions.Regex.Match(Input,“\d{2}th\s*\w+,\s*\d{4}”).Value

InputDateTimeString =InputDateTimeString.Replace(“th”,“”)

ConvertedDate = DateTime.ParseExact(InputDateTimeString, “dd MMMM, yyyy”, System.Globalization.CultureInfo.InvariantCulture).ToString( “dd.MM.yyyy”)

Write Line activity:
Text: ConvertedDate

@Ajinya_jorwekar

take assign

Str_Effective Date = “20th October, 2023"

syntax

DateTime.ParseExact(System.Text.RegularExpressions.Regex.Match(Str_Effective Date ,“\d{1,2}(th)\s[A-z]+(,\s)\d{4}”).Value.replace(“th”,“”).Replace(“,”,“”),{“dd MMMM yyyy”},nothing).ToString(“dd.MM.yyyy”)

DateTime.ParseExact(System.Text.RegularExpressions.Regex.Match(Str_Effective Date ,"\d{1,2}(th)\s[A-z]+(\,\s)\d{4}").Value.replace("th","").Replace(",",""),{"dd MMMM yyyy"},nothing).ToString("dd.MM.yyyy")

cheers…!

strinput=system.Text.RegularExpressions.Regex.Match(strinput,“(\d{1,2}(st|nd|rd|th) [a-zA-Z]+, \d{4})”).tostring.Replace(“th”,“”).Replace(“,”,“”)

outputstr=datetime.ParseExact(strinput,“dd MMMM yyyy”,system.Globalization.CultureInfo.InvariantCulture).ToString(“dd.MM.yyyy”)

Maybe this more granular pattern will help for extraction and Parsing:


And referring to groups
grafik

(?<=Effective from )(\d+)(?:[\sa-z]+)([A-Za-z]+)(?:[,\s]+)(\d+)

[CheatSheet] - System.Text.RegularExpressions | RegEx - News / Tutorials - UiPath Community Forum

So we can use the groups also for the String to DateTime Conversion when we do need it

EDITED: added an extended series below:

1 Like

Hey @Ajinya_jorwekar ,

Use an assign activity and paste the below code in the “Value To Save” field.

Also In the below expression, Replace the YourString with your string value

DateTime.ParseExact(System.Text.RegularExpressions.Regex.Match(YourString,"\d{1,2}(th)\s[A-z]+(\,\s)\d{4}").Value.replace("th","").Replace(",",""),{"dd MMMM yyyy"},nothing).ToString("dd.MM.yyyy")

Hope it helps you out!

Thanks All @Vikas_M
@Shiva_Nikhil @sai_gupta

1 Like

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