Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SSIS expression: convert date to string

Tags:

I'm new to SSIS and I'm trying to convert a GetDate() to string "DD-MM-YYYY". This is the expression I've built so far:

(DT_WSTR, 8)  DAY( GETDATE()) + "-" + (DT_WSTR, 8)  (MONTH(GETDATE()) - 1) + "-" + (DT_WSTR, 8) YEAR(GETDATE()) 

The problem I've got is Month() converts the Month "23-4-2013" to a single character when I want it in Double character, same as day. How do i make it into a double character no matter what month it is?

like image 485
resolver101 Avatar asked May 23 '13 10:05

resolver101


People also ask

How do I convert datetime to date in SSIS?

To convert Datetime to Date, we have to use "DT_DBDATE" data type.

What is Dt_numeric in SSIS?

(DT_NUMERIC,10,3) casts a numeric value to the DT_NUMERIC data type using a precision of 10 and a scale of 3. (DT_TEXT,1252) casts a value to the DT_TEXT data type using the 1252 code page.

How do I concatenate an expression in SSIS?

To concatenate two numeric values, both numeric values must be explicitly cast to a string data type. A concatenation can use only one BLOB data type: DT_TEXT, DT_NTEXT, or DT_IMAGE. If either element is null, the result is null. String literals must be enclosed in quotation marks.


1 Answers

For SSIS you could go with:

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("yy" , GETDATE()) 

Expression builder screen:

Expression builder screen

like image 172
Milen Kindekov Avatar answered Sep 23 '22 18:09

Milen Kindekov