After looking to the sample you provided in your question your datetime format is (HH:mm
,H:mm
), so you can achieve this using an SSIS package and writing a VB.net script into it as the following:
- Create a
Flat File connection manager
and an OLEDB Connection Manager
(Source and Destination)
- Add a
DataFlow Task
- In the
DataFlow Task
add a Flat File Source
, Script Component
, OLEDB Destination
- your DataFlow should look like
Source --> Script --> Destination
- In the Script component Mark the Time column as input( assuming it's name is
inTime
) and add an Output Column (ex: OutTime
) of Time DT_DBTIMESTAMP
In the Script Write The Following Code: (using Vb.net)
Public Overrides Sub Input0_ProcessInputRow(ByVal Row As Input0Buffer)
If Not Row.inTime_IsNull AndAlso _
Not String.IsNullOrEmpty(Row.inTime.Trim) Then
Row.OutTime = DateTime.ParseExact(Row.InTime.Trim,New String(){"HH:mm","H:mm"},New System.Globalization.CultureInfo("En-GB"), System.Globalization.DateTimeStyles.None)
Else
Row.OutTime_IsNull = True
End If
End Sub
C# Version (used Telerik converter)
public override void Input0_ProcessInputRow(Input0Buffer Row)
{
if (!Row.inTime_IsNull && !string.IsNullOrEmpty(Row.inTime.Trim()))
{
Row.outTime = DateTime.ParseExact(Row.inTime.Trim(), new string[] {
"HH:mm",
"H:mm"
}, new System.Globalization.CultureInfo("En-GB"), System.Globalization.DateTimeStyles.None);
}
else
{
Row.outTime_IsNull = true;
}
}
When Parsing a Time Value as a Date it will add by default Today Date to it.
- In the
OLEDB Destination
Map OutTime
Column to the Destination Column