Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SOS! query for date within string 1

Status
Not open for further replies.

panini

MIS
Jun 1, 2001
136
GB
Hi there,

I need to pull the first date out of a string that looks like this

Mr. Boris Mackay * DOB: 12/11/1940 :: Mrs. Sheila Mackay * DOB: 11/10/1956

and check the DOB against another date to make sure they aren't over 65....

(I'm using ... AND (DATEDIFF([year], customer.DOB, orders.closeDate) > '65') for that bit)

does anyone know how i can pull that first date out of the string in my query?

many thanks,

 
This will get you started, modify for your own use

declare @v varchar(100)
select @v ='Mr. Boris Mackay * DOB: 12/11/1940 :: Mrs. Sheila Mackay * DOB: 11/10/1956'

select Substring(@V,(CHARINDEX('/',@v,1)-2),10)

nb

This assumes your dates are in this format 02/01/1940
not 2/1/1940

Denis The SQL Menace
SQL blog:
Personal Blog:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top