Yesterday's date in SSIS package setting in variable through expression

Mytroy2050 picture Mytroy2050 · Nov 8, 2014 · Viewed 18.2k times · Source

I am setting a variable in SSIS package and I'm using this expression:

DATEPART("yyyy", GETDATE())*10000 
        + DATEPART("month", GETDATE())*100  
        + DATEPART("day",GETDATE())

The expression will give me a variable value like 'yyyymmdd'. My problem is that I want yesterday's date.

For example on 11/1/2014 it should be 20141031

Answer

Rangani picture Rangani · Nov 10, 2014

You can use DATEADD function your expression would be :

DATEPART("yyyy", DATEADD( "day",-1, GETDATE()))*10000 + DATEPART("month",  DATEADD( "day",-1, GETDATE())) * 100 + DATEPART("day", DATEADD( "day",-1, GETDATE()))