datesql-server-2005typesssisssis-2005

Get previous day in an Expression


Just need help on this as I am new at SSIS. I got an expression but I want yesterday, not today.

 "Daily "+ (RIGHT("0" + (DT_STR,4,1252) DatePart("yyyy",getdate()),4))+(RIGHT("0" + (DT_STR,4,1252) DatePart("mm",getdate()),2))+(RIGHT("0" + (DT_STR,4,1252) DatePart("dd",getdate()),2))+".CSV"

Currently it looks like this

Daily 20161006.CSV

What I want is

Daily 20161005.CSV


Solution

  • Here you go.

    "Daily "
    + (DT_WSTR, 4) YEAR(DATEADD("day",-1,GETDATE()))
    + RIGHT("0" + (DT_WSTR, 2) DATEPART("MM", DATEADD("day", -1, GETDATE())),2)
    + RIGHT("0" + (DT_WSTR, 2) DATEPART("DD", DATEADD("day", -1, GETDATE())),2)
    + ".CSV"
    

    It looks like you are in Australia, so it is 20161006 there, but in US Right now, it is 20161005, and see how it shows yesterday i.e. 20161004 in the file name when I clicked Evaluate value

    enter image description here