Regex to get Datetime from a string

Hello All,

need regex to extract datetime from a string.

example string is :Private Residence
Delivered 01/24/2023 01:38 PM
Recvd by: BRENT M
Appointment scheduled for 01/24/2023 08:00 AM - 04:00 PM
Charges: View charges here

but need only 01/24/2023 01:38 PM

i am suing C# language for UiPath Studio.

thanks in advance.

few more input string sample

sample 1: Shipment Canceled 02/01/2023

sample 2: Delivered 01/23/2023 01:33 PM
Recvd by: GARCIA
Appointment scheduled for 01/23/2023 01:33 PM
Charges: View charges here
COD Amount:


Hi @sudha456,
Please use below regex to extract the value

\d{2}\/\d{2}\/\d{4} \d{2}:\d{2} (AM|PM)

To get the date value using below syntax in assign activity

strDate=System.Text.RegularExpressions.Regex.Match(yourString,"\d{2}\/\d{2}\/\d{4} \d{2}:\d{2} (AM|PM)").Value



Hello Arivu96,

thanks for the quick response.
I tried the same but it sthrowing an exception.

i am suing C# langague to build the project. it might be working for but not for C#.


Please use like this

System.Text.RegularExpressions.Regex.Match("",@"\d{2}/\d{2}/\d{4} \d{2}:\d{2} (AM|PM)").Value

Feel free to mark solution if working else happy to help

Hope this helps


Hello Anil,

thanks for quick support.

its working fine when we have AM or PM but returing null when input string does not have those


So according to what we did…it matches the expression only when all of those are present…Else it would be null only…Does some dates dont have AM or PM? if do use the below expression

\d{2}/\d{2}/\d{4} \d{2}:\d{2}


Thanks a lot,

can i get one more regex to get date when input contains only MM/dd/yyyy?

Thanks a lot


This is for date


You can actually match all of those 4 patternn together using this

\d{2}/\d{2}/\d{4}( \d{2}:\d{2})*( AM| PM)*

Hope this helps


its working fine .

thanks a lot


Happy Automation


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