SSIS package how to add date/timestamp to file name each time package run

Viewed 26096

i have a SSIS package that outputs a csv file to a location this package will be run on a daily basis.at the moment I look if a file exists and if it does I delete it before creating a new one so that I don't get any errors with creating a file that already exists - what I want to do is create a new csv and add a date/timestamp to the end of file name. I'm not sure how I go about achieving this.

1 Answers

You can achieve this using the following steps:

  1. Add a variable i.e. User::Filename
  2. Click on the variable, and press F4 to show the properties Tab
  3. In the Expression use an expression similar to the following:

    "C:\\Filename_" + (DT_WSTR,4)YEAR(GETDATE()) + "_" + (DT_WSTR,4)MONTH(GETDATE()) + "_" + (DT_WSTR,4)DAY(GETDATE()) + ".csv"
    
  4. In the Destination Flat File Connection manager, in the expressions (found in the property tab) use this variable as a Connection String expression

    @[User::Filename]
    
Related