Quantcast
Channel: SQLServerCentral » SQL Server 2014 » Development - SQL Server 2014 » Latest topics
Viewing all articles
Browse latest Browse all 3145

find date value from file name

$
0
0
Hello,I am trying to write an expression in SSIS to see if the file is older than 7 days then delete it.The problem is my file names are not consistent here. Like abc_vg-20161204.txt or bhagvskjhads_ghasgh_sahsa-20161104.txt So whats consistent is every file name has "-" and after that only the datetimestamp.I am taking baby steps to write this.[code="sql"]DECLARE @Filename_to_be_deleted varchar(100)DECLARE @Filemaxage intSET @Filename_to_be_deleted = 'abc_vg-20161204.txt'SET @Filemaxage = 7SELECT CHARINDEX('-',@Filename_to_be_deleted)SELECT SUBSTRING(CHARINDEX('-',@Filename_to_be_deleted),6,2)SELECT DATEDIFF('dd',(DT_Date)(SUBSTRING(@Filename_to_be_deleted,6,2) + "-" + SUBSTRING(@Filename_to_be_deleted,8,2) + "-" + SUBSTRING(@Filename_to_be_deleted,10,4)),GETDATE()) > @Filemaxage[/code]Now with charindex I can find the position of "-" but then how to retrieve the datepart from file name and compare?Please let me know thanks.

Viewing all articles
Browse latest Browse all 3145

Trending Articles