Extract date from string

below are the two sample, how to Extract date convert in mm/dd/yyyy format from below strings

07 May 2022 04:46

Brisbane, Queensland, Australia 05 May 2022, 13:31 EAST (Actual)

Hi,

Can you try the following expression?

DateTime.Parse(System.Text.RegularExpressions.Regex.Match(yourString,"\d{2}\s+(JAN|FEB|MAR|APR|MAY|JUN|JUL|AUG|SEP|OCT|NOV|DEC)\s+\d{4}",System.Text.RegularExpressions.RegexOptions.IgnoreCase).Value).ToString("MM/dd/yyyy")

Regards,

Hi @Yoichi,
What will be the output for this statement? will it be mm/dd/yyyy or MM/dd/yyyy?

I am trying to get below outputs

05/07/2022

05/05/2022

Hi,

"mm" means 2 digit minute.
"MM" means 2 digit month.

I think you need "MM/dd/yyyy" format as the above expression.

Regards,

1 Like

Hey!

Extract the date like this:

Assign strDate = System.Text.RegularExpressions.RegEx.Match(StrVariable,"\d{2,}.[A-Za-z].+\d{4}").ToString

The above expression will give you the below format

05 May 2022

Reference:

You have to convert this to the required format like this

Assign dateFinalDate = Datetime.ParseExact(strDate.ToString, "dd MMM yyyy", System.Globalization.CultureInfo.InvariantCulture).ToString("MM/dd/yyyy")

The above expression will give you the date like this

05/05/2022

Regards,
NaNi

1 Like

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