I have an SSIS Script component that needs to run some VB.NET code shortly before it exports data.
I’m feeding this script component each row of a timestamp column. (datatype DT_DBTIMESTAMP)
The input style of the date is as follows: 2012-09-12 16:34:12
I need the VB.NET code to change this so it shows in the format: 09/12/2012 04:34:12 PM
The two key points being that all values need to be padded with a zero if they’re single digits, and all time values need to be in 12 hour format with AM/PM. In short, the style must follow: {0:MM/dd/yyyy hh:mm:ss tt}
Unfortunately, I have very limited VB.NET skills, and I have yet to find an example of this on SO or MSDN. From my searching, it appears I might be able to create a new style of DateTime object and then use a custom date format or something? I can’t for the life of me figure out what to do here.
The autogenerated code from the script component is as follows:
Imports System
Imports System.Data
Imports System.Math
Imports Microsoft.SqlServer.Dts.Pipeline.Wrapper
Imports Microsoft.SqlServer.Dts.Runtime.Wrapper
Public Class ScriptMain
Inherits UserComponent
Public Overrides Sub Input0_ProcessInputRow(ByVal Row As Input0Buffer)
'
' Add your code here
'
End Sub
End Class
So could I do something like:
String.Format("{0:MM/dd/yyyy hh:mm:ss tt}", Row.[DateTimeColumn].toString())
I dunno…totally lost here. First time using script components in SSIS or VB.NET really.
Help???? 🙁
If you get the data as a
Dateobject, then you can simply call theToStringmethod and pass the format string, for instance:However, if you get the date as a string, then you need to first parse it into a
Dateobject before reformatting it: