SQL Server – How to Extract Only Date from String

sql server

I have one field in database and I am getting the multiple dates in the same field. I want to extract multiple dates from the string. Please help me on this
String like:

"7/3/2019 1:20 AM – Request submitted by Ekaterina Rahul 7/3/2019 1:34 AM – Request assigned to 7/3/2019 3:22 AM – PO123456 created"

Best Answer

With the string you have in your example, you can use STRING_SPLIT as the first step

DECLARE @tags NVARCHAR(400) = '7/3/2019 1:20 AM - Request submitted by Ekaterina Rahul 7/3/2019 1:34 AM - Request assigned to 7/3/2019 3:22 AM - PO123456 created'  

SELECT value  
FROM STRING_SPLIT(@tags, '-')  
WHERE RTRIM(value) <> '';

Which gives results

value
7/3/2019 1:20 AM 
Request submitted by Ekaterina Rahul 7/3/2019 1:34 AM 
Request assigned to 7/3/2019 3:22 AM 
PO123456 created

You could then use RIGHT and or TRIM to leave only the dates

Select RIGHT ( ' Request submitted by Ekaterina Rahul 7/3/2019 1:34 AM ' , 18 ) 

Gives

7/3/2019 1:34 AM 

If you want them to be dates at the end, you would need to use CAST / CONVERT to change the string to date format.