Dynamic file names

  • Hello All,

    Iam trying to retrieve the previous day file placed in FTP location.

    Iam using the expression below for getting the file name

    "Filename "+ RIGHT( "0"+ (DT_WSTR, 2) MONTH( DATEADD("mm", 0, GETDATE()) ) , 2 ) + "-"+ RIGHT( "0"+ (DT_WSTR, 2) DAY( DATEADD("dd", -1, GETDATE()) ) , 2 ) + "-"+ (DT_WSTR, 4) YEAR( GETDATE() )+".csv"

    Problem I have though is while my expression provides me with a previous date.It fails when moving into another month for example on March 1, 2012 I would expect the expression to evaluate to Feb 29, 2012, instead it evaluates to March29, 2012 it handles the date difference within a given month correctly.

    Your help would be highly appreciated.

    Thanks in Advance

  • It seems that the file name you are looking for contains yesterday's date:

    Today: 3/1/2012

    Expected Expression Output: Filename 02-29-12.csv

    If that's correct, I'd suggest first subtracting the day to get the date you want and then deal with the formatting. In two steps, using variables that evaluate as expression:

    Variable: StrYesterday defined as string

    Variable: StrFileName defined as string

    Expressions:

    StrYesterday: (DT_WSTR, 10) (DT_DBDATE) DateAdd("dd",-1,GetDate())

    StrFileName: "Filename " + Substring(@[User::StrYesterday],6,5) + "-" + Substring(@[User::StrYesterday],3,2) + ".csv"

    I've found the DT_DBDATE type cast to be useful because it returns a date in YYYY-MM-DD format without the time stamp.

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply