Quantcast
Channel: convert string to date
Viewing all articles
Browse latest Browse all 10

convert string to date

$
0
0

HI

create table #a
(
ID INT IDENTITY(1,1) PRIMARY KEY
, [fileName] VARCHAR(100)
)

INSERT INTO #a([fileName])
VALUES
('abcd_efgh_stry_2018-11-02.xml')
, ('ghjk_tfgh_2018-11-02.xml');

--select * from #a;

SELECT *,CAST(REVERSE(SUBSTRING(REVERSE(FILENAME),5,CHARINDEX('_',REVERSE(FILENAME),1)-5)) AS DATE)DD FROM #A

Thanks


Viewing all articles
Browse latest Browse all 10

Trending Articles