Mike
Mike

Reputation: 1938

How to create a file with the current date appended in a SSIS package

I have created an SSIS package and almost have it completed.

I am to the point where I'm trying to take the data that I've put into an Excel file and copy the file and rename it at the same time.

Basically, I have a file InboundScrapWeights.xlsx that I am copying to its final resting place. This location has a lot of other files that have the same name, but with the date they were created on the end so that they look like this: InboundScrapWeights_20180216.xlsx.

I've got a File System Task that is copying the file, but I cannot see how to append the date to the end of the file name. How do I get the date on there?

Upvotes: 2

Views: 1961

Answers (1)

KeithL
KeithL

Reputation: 5594

  • string variable fname
  • string variable strDate

expressions:

fname

"InboundScrapWeights_" + @strDate + ".xlsx"

strDate

(DT_STR, 4, 1252) DATEPART("yyyy" , GETDATE())
+ RIGHT("0" + (DT_STR, 2, 1252) DATEPART("mm" , GETDATE()), 2)
+ RIGHT("0" + (DT_STR, 2, 1252) DATEPART("dd" , GETDATE()), 2)

In FileTask destination is variable = true

set variable to fName (you proably need full path)

Upvotes: 3

Related Questions