Convert date
How I can convert a datetime to date?
Column - DataType: DT_DBTIMESTAMP
dd.mm.yyyy ss.mm.hh (20.01.2011 00:00:00) -> dd.mm.yyyy (only 20.01.2011) german
witht Derived Column Transformation or Script ?
January 20th, 2011 8:34am
In a derived column transformation you can use (DT_DBDATE) .Russel Loski, MCT
Free Windows Admin Tool Kit Click here and download it now
January 20th, 2011 8:46am
expression: (DT_DBDATE)column-datetime | DataTyp: databasetimestamp[DT_DBTIMESTAMP]
result: 20.01.2011 00:00:00
January 20th, 2011 8:54am
Are you trying to convert to a string or to a date data type? If you are converting to a date data type, SQL Server will ignore the time. If you are converting to a date string then you will need something like:
RIGHT( "0" + (DT_STR, 2, 1252) DAY( column-datetime ) , 2) + "." + RIGHT( "0" + (DT_STR, 2, 1252) MONTH(
column-datetime ) , 2) + "." + (DT_STR, 4, 1252) YEAR (
column-datetime )Russel Loski, MCT
Free Windows Admin Tool Kit Click here and download it now
January 20th, 2011 9:03am
It doesn't work :-(
Insert in expression:
RIGHT( "0" + (DT_STR, 2, 1252) DAY(firstdate) , 2) + "." + RIGHT( "0" + (DT_STR, 2, 1252) MONTH(firstdate) , 2) + "." + (DT_STR, 4, 1252) YEAR (firstdate)
result: 20.01.2011 00:00:00 (CSV)
SSIS-Package | Data Flow:
1 DataReader-Source(ODBC)
2 Derived Column Transformation
3 Flatfile Destination (CSV-File)
DataReader-Source(ODBC):
- out-column 'firstdate' > datatype: DT_DBTIMESTAMP
- out-column 'lastedate' > datatype: DT_DBTIMESTAMP
January 20th, 2011 9:30am
My solution:
Data Conversion
DataType [DT_DBTIMESTAMP] -> [DT_DATE]
CSV (column): 20.01.2011 (only date 'firstdate' and 'lastdate') :-)
Free Windows Admin Tool Kit Click here and download it now
January 20th, 2011 9:49am
Change the datatype of the firstdate and the lastdate column in the flat file connection manager to string and not dbdate or dbtimestamp. Then use the string version of the expressionRussel Loski, MCT
January 20th, 2011 9:50am
I have change the datatype in the flat file connection manager.
firstdate and lastdate -> Date[DT_Date]
Free Windows Admin Tool Kit Click here and download it now
January 20th, 2011 10:05am
Andy - the Derived Column will work, as will the Data Conversion and changing the data type in the connection manager.
Casting didn't work for you in the Derived Column because you casted the value in the column to a DT_DBDATE, but placed the result right back into the column that's defined as a DT_DBTIMESTAMP - and that converts it back again. You need to "create
a new column" if you're going to do that with the Derived Column component.
Talk to me now on
January 21st, 2011 5:16pm