2016-09-12 127 views
1
--My Age format will be like '056Yrs03Mths13Days/Male' 

DECLARE @INPUT VARCHAR(250),@DATE_OF_BIRTH DATETIME, 
@YEARS BIGINT , @MONTHS BIGINT ,@DAYS BIGINT 


set @INPUT='056Yrs03Mths13Days/Male' --My INPUT age format will be like this. 

SET @YEARS=CONVERT(BIGINT,SUBSTRING(@AGE_NME,1,3)) 
--select @YEARS 

SET @MONTHS=CONVERT(BIGINT,SUBSTRING(@AGE_NME,CHARINDEX ('M',@AGE_NME,1)-2,2)) 
--SELECT @MONTHS 

SET @DAYS=CONVERT(BIGINT,SUBSTRING(@AGE_NME,CHARINDEX ('D',@AGE_NME,1)-2,2)) 
--SELECT @DAYS 


SET @DATE_OF_BIRTH= ? 
+0

我想要的確切日期上面的輸入params.please幫我出來 –

+1

爲什麼你把它標記爲MySQL? – cha

回答

0
SET @YEARS=CONVERT(BIGINT,SUBSTRING(@INPUT,1,3)) 

SET @MONTHS=CONVERT(BIGINT,SUBSTRING(@INPUT,CHARINDEX ('M', @INPUT,1)-2,2)) 

SET @DAYS=CONVERT(BIGINT,SUBSTRING(@INPUT,CHARINDEX ('D', @INPUT,1)-2,2)) 

SET @DATE_OF_BIRTH=DATEADD(year, [email protected], 
DATEADD(month, [email protected],DATEADD(day, [email protected], getDate()))) 
SELECT Convert(nvarchar(12),@DATE_OF_BIRTH,105) 
相關問題