Philip
Philip

Reputation: 2628

SSIS Variable with formated time

I have the following code within an expression that produces a directory path and a file name with Adjustment_09_02_2019.csv for example.

 @[User::DestinationDirectory] 
   + "\\Adjustment_"
   + RIGHT("0" + (DT_STR, 2, 1252) DATEPART("dd" , GETDATE()), 2)
   + "_"
   + RIGHT("0" + (DT_STR, 2, 1252) DATEPART("mm" , GETDATE()), 2)
   + "_"
   + (DT_STR, 4, 1252) DATEPART("yyyy" , GETDATE())
   + ".csv"

How could I adjust this so I get the file name as Adjustment_09_02_2019_16_55_02.csv so the time is on the end of the file name too?

Upvotes: 3

Views: 33

Answers (1)

Alexander Volok
Alexander Volok

Reputation: 5940

I think you are already quite close to a desired result. The time part can be generated via:

+ "_"
+ RIGHT("0" + (DT_STR, 2, 1252)DATEPART("hh", GETDATE()), 2) + "_"
+ RIGHT("0" + (DT_STR, 2, 1252)DATEPART("mi", GETDATE()), 2) + "_"
+ RIGHT("0" + (DT_STR, 2, 1252))DATEPART("ss", GETDATE()), 2) 

Therefore the full expression can be similar to:

@[User::DestinationDirectory] 
+ "\\Adjustment_"
+ RIGHT("0" + (DT_STR, 2, 1252) DATEPART("dd" , GETDATE()), 2)
+ "_"
+ RIGHT("0" + (DT_STR, 2, 1252) DATEPART("mm" , GETDATE()), 2)
+ "_"
+ (DT_STR, 4, 1252) DATEPART("yyyy" , GETDATE())
+ "_"
+ RIGHT("0" + (DT_STR, 2, 1252)DATEPART("hh", GETDATE()), 2) 
+ "_"
+ RIGHT("0" + (DT_STR, 2, 1252)DATEPART("mi", GETDATE()), 2) 
+ "_"
+ RIGHT("0" + (DT_STR, 2, 1252)DATEPART("ss", GETDATE()), 2)
+ ".csv"

Upvotes: 2

Related Questions