Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

ssis

msbi

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

like image 978
Mytroy2050 Avatar asked Nov 08 '14 18:11

Mytroy2050


2 Answers

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()))
like image 189
Rangani Avatar answered Sep 20 '22 23:09

Rangani


This will give yesterday's date

(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)

like image 43
Saju Avatar answered Sep 18 '22 23:09

Saju