sql - Finding a very first Date occurrence in a string -
i have interesting task of finding first date value in text field. there no identifiers, date come in various formats such '01/01/2015', '1/1/2015', 1/1/15', '1/01/15', etc. format month, day, year; however, vary mm/dd/yyyy, mm/dd/yy, m/dd/yyyy, etc.
for example:
the rain in spain falls on 01/01/2015 , ends between 03/02/2015 , 04/01/2015.
i want capture "01/01/2015", because first date occurrence in string.
trying figure out easiest way extract first date occurrence, no such luck of yet. suggestions?
tks!
ok work or @ least place start:
you can find out more string functions here
declare @st varchar(max) = 'the rain in spain falls on 1/1/2015 , ends between 03/02/2015 , 04/01/2015' select substring(@st,patindex ( '%[0-9]%/%[0-9]/%[0-9]%' , @st ),patindex ('%[a-z]%', substring(@st,patindex ( '%[0-9]%/%[0-9]/%[0-9]%' , @st ),len(@st)))-1)
Comments
Post a Comment