I have the following string:Un texto cualquiera 22/12/2016 fin texto
I am trying to get the position of 22/12/2016
with the PATINDEX function:
SELECT PATINDEX('__/__/____', 'Un texto cualquiera 22/12/2016 fin texto');
But the function returns 0, do you know what I'm doing wrong?
The underscore _
according to the microsoft link is for one character. patterns
Greetings nachfren , considering that the date format is dd/mm/yyyy , this will be useful:
Resulting:
The present code will not work if the format changes as d/m/yyyy or dd/m/yyyy or d/mm/yyyy . I hope you made me understand, if not, hit the comments and we'll see how we support you brother :D
I think the problem is that the character is missing
%
This pattern would only be valid for this string
'22/12/2016'
because it has no way of identifying multiple characters.If we change it to
It should work now