Anyone who reads this blog regularly knows I am a big fan of using expressions to achieve results in SSIS. In this post I'm going to show a very simple example of using them.
If you are building SSIS packages then you will be (or you should be) using the log providers to keep a history of your package executions. I generally use the Log Provider for Text Files:

One thing I like to do is have a seperate logfile for each execution of a package. I also like to easily identify which package the logfile was created by. Well guess what, all of this can be achieved with expressions.
Take the File Connection Manager that is used to point at the location where SSIS will create the logfile. I can apply an expression to the ConnectionString property in order to achieve what I want. Here is the expression:
"C:\\temp\\" + @[System::PackageName] +
(DT_STR,4,1252)DATEPART( "yyyy" , @[System::StartTime] ) +
RIGHT("0" + (DT_STR,4,1252)DATEPART( "mm" , @[System::StartTime] ), 2) +
RIGHT("0" + (DT_STR,4,1252)DATEPART( "dd" , @[System::StartTime] ), 2) +
RIGHT("0" + (DT_STR,4,1252)DATEPART( "hh" , @[System::StartTime] ), 2) +
RIGHT("0" + (DT_STR,4,1252)DATEPART( "mi" , @[System::StartTime] ), 2) +
RIGHT("0" + (DT_STR,4,1252)DATEPART( "ss" , @[System::StartTime] ), 2) +
".csv"
The bit that people have trouble with here is getting the date and time in the required format [YYYYMMDDHH24MISS] that will ensure the files appear in the order that they are created. Hopefully my putting this expression here will make it easier for people. In the screenshot below you can see the expression and what it is evaluating to:

Just to prove the point, here's a screenshot of the c:\temp directory after a few executions:

Hope that's useful to someone. In all probability the most useful thing is the expression to return today's date as a string. Of course, this technique can also be used for other files, not just log files.
The demo package can be downloaded from here.
-Jamie