Reputation: 144
I have a SQL table with few fields.
id, Date, Description, etc
The description is a string where people add some content..
Example 1: Pista Automobilistica Con Automobili 500 04/07/1957 , Poi Le 500
Example 2: Context date: 09/02/1979.. text text..
I need to extract the date (d/m/y
) from the text and copy it to de Date column in sql format (y/m/d
)
Upvotes: 0
Views: 1088
Reputation: 26
-- This query return the date of the column descrip (only one date by string)
select str_to_date(substr(descrip,instr(descrip,'/')-2,10),'%d/%m/%Y') as fecha from tabla;
Upvotes: 1
Reputation: 194
--This is for MSSQL Server, I hope you got the idea
declare @str1 varchar(max),@str2 varchar(max),@str3 varchar(max)
set @str1='Pista Automobilistica Con Automobili 500 04/07/1957 , Poi Le 500'
set @str2='Context date: 09/02/1979.. text text..'
set @str3='xzczxczxczxcxzc 12/12/2018 xcvxcvxc'
print convert(date,substring(@str1,CHARINDEX('/',@str1,1)-2,10),101)
print convert(date,substring(@str2,CHARINDEX('/',@str2,1)-2,10),101)
print convert(date,substring(@str3,CHARINDEX('/',@str3,1)-2,10),101)
Upvotes: 0