SSIS - script component DateTime Formats Implicit Conversion
General Info
These are the default formats of datetimes datatypes (when converting from string)
DT_DBDATE
yyyy-mm-dd
DT_FILETIME
yyyy-mm-dd hh:mm:ss:fff
DT_DBTIME
hh:mm:ss
DT_DBTIME2
hh:mm:ss[.fffffff]
DT_DBTIMESTAMP
yyyy-mm-dd hh:mm:ss[.fff]
DT_DBTIMESTAMP2
yyyy-mm-dd hh:mm:ss[.fffffff]
DT_DBTIMESTAMPOFFSET
yyyy-mm-dd hh:mm:ss[.fffffff] [{+|-} hh:mm]
Note: DT_DATE and DT_DBTIMESTAMP has the same SET method And i think that converting string to date is depending also on your current culture info More detailed information are found here
Experiments :
I didn't find any related article on this issue so i made the following experiments:
SSIS Implicit datetime Conversion
i created a SSIS package with a Dataflowtask. in this dataflowtask i created a Script Component (as a Source) and a Flat File Destination. The script has one output column `OutDate` of type `DT_DbTimeStamp` Inside the script i used the following code:
First i am looping over all culture info and i am Getting all datetime formats related to it and looping over them. Then i am trying to convert the date `dtDate` declared to a formatted string and assign it to the Output column.
So if assigning string value with specified format to DT_DBTIMESTAMP output column is accepted that means the format is implicit converted
And Here is the Link of the Result File:
- https://www.dropbox.com/s/0f1kmbzgh78fkxw/Result.txt?dl=0
This article is posted as an answer on Stackoverflow at Feb 4 2017
These are the default formats of datetimes datatypes (when converting from string)
DT_DBDATE
yyyy-mm-dd
DT_FILETIME
yyyy-mm-dd hh:mm:ss:fff
DT_DBTIME
hh:mm:ss
DT_DBTIME2
hh:mm:ss[.fffffff]
DT_DBTIMESTAMP
yyyy-mm-dd hh:mm:ss[.fff]
DT_DBTIMESTAMP2
yyyy-mm-dd hh:mm:ss[.fffffff]
DT_DBTIMESTAMPOFFSET
yyyy-mm-dd hh:mm:ss[.fffffff] [{+|-} hh:mm]
Note: DT_DATE and DT_DBTIMESTAMP has the same SET method And i think that converting string to date is depending also on your current culture info More detailed information are found here
- https://msdn.microsoft.com/en-us/library/ms141036.aspx
- http://www.bidn.com/blogs/DevinKnight/ssis/1387/ssis-to-sql-server-data-type-translations
Experiments :
I didn't find any related article on this issue so i made the following experiments:
SSIS Implicit datetime Conversion
i created a SSIS package with a Dataflowtask. in this dataflowtask i created a Script Component (as a Source) and a Flat File Destination. The script has one output column `OutDate` of type `DT_DbTimeStamp` Inside the script i used the following code:
Private dtDate As Date = #01/01/2016#
Public Overrides Sub CreateNewOutputRows()
Output0Buffer.AddRow()
Using sw As New IO.StreamWriter("D:\Result.txt", False)
sw.WriteLine("CultureInfo;Date;Format;Accepted")
sw.Close()
End Using
For Each ci As System.Globalization.CultureInfo In System.Globalization.CultureInfo.GetCultures(Globalization.CultureTypes.AllCultures)
For Each strFormat As String In ci.DateTimeFormat.GetAllDateTimePatterns
Dim boolResult As Boolean = True
Try
Output0Buffer.OutDate = dtDate.ToString(strFormat)
boolResult = True
Catch ex As Exception
boolResult = False
End Try
Using sw As New IO.StreamWriter("D:\Result.txt", True)
sw.WriteLine(ci.Name & ";" & dtDate.ToString(strFormat) & ";" & strFormat & ";" & boolResult.ToString)
sw.Close()
End Using
Next
Next
End Sub
First i am looping over all culture info and i am Getting all datetime formats related to it and looping over them. Then i am trying to convert the date `dtDate` declared to a formatted string and assign it to the Output column.
So if assigning string value with specified format to DT_DBTIMESTAMP output column is accepted that means the format is implicit converted
Output0Buffer.OutDate = dtDate.ToString(strFormat)
And Here is the Link of the Result File:
- https://www.dropbox.com/s/0f1kmbzgh78fkxw/Result.txt?dl=0
This article is posted as an answer on Stackoverflow at Feb 4 2017