Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 870
Philip Avatar asked May 27 '26 19:05

Philip


1 Answers

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"
like image 92
Alexander Volok Avatar answered May 30 '26 08:05

Alexander Volok



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!