I saw so many people using the following expression in naming their file name.
"\\myPath\\myFolder\\myFile_" + (DT_WSTR, 4) YEAR( GETDATE() ) + (DT_WSTR, 2)MONTH( GETDATE() ) + (DT_WSTR, 2) DAY( DATEADD("d", -SomeDays, GETDATE()) ) + ".txt"
I would like to point out an issue that I had found with this expression.
Let' say today is 03 September 2010, and SomeDays = -1. Then the result of the expression will be "\\myPath\\myFolder\\myFile_20100902.txt", which is correct.
How about if SomeDays = -3, the result will be "\\myPath\\myFolder\\myFile_20100931.txt". Can you spot the mistake?
That's right, the day is correct. BUT, the month is incorrect. It should be 08 instead of 09. And this could happen with the YEAR too if you're using DATEADD for month.
To avoid this issue, simply uses DATEADD(<date interval>, -Somedays, GETDATE() ), in YEAR, MONTH and DAY.
I hope this helps.
View Complete Post