How I can change a file name with code in SSIS

Van Alstyne 20 Reputation points
2025-06-16T20:32:08.67+00:00

I'm trying to change a file name to current year and Previous month with below script but it is still coming as current year and current month. I tried around to fix it but no luck.

If anyone can show my mistake please

"D:\Sales" + (DT_WSTR,4)DATEPART("yyyy",GetDate()) +

RIGHT("0" + (DT_WSTR,2)DATEPART("mm",GetDate()) ,2) + ".csv"

SQL Server Integration Services
SQL Server Integration Services
A Microsoft platform for building enterprise-level data integration and data transformations solutions.
2,700 questions
{count} votes

Accepted answer
  1. Harshit patidat 80 Reputation points
    2025-06-17T17:26:57.39+00:00

    "D:\Sales" +

    (DT_WSTR,4)DATEPART("yyyy", DATEADD("month", -1, GETDATE())) +

    RIGHT("0" + (DT_WSTR,2)DATEPART("mm", DATEADD("month", -1, GETDATE())), 2) +".csv"

    1 person found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Newest

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.