damola
damola

Reputation: 292

Convert string to Date in ssis

I have tried converting a date in the format 23/12/2001 to 2001-12-23 using the following in ssis but I keep getting an error.

ISNULL(Date_Of_Birth) ? NULL(DT_DBTIMESTAMP) : (DT_DBTIMESTAMP)
(SUBSTRING(Date_Of_Birth,FINDSTRING(Date_Of_Birth,"/",2) + 1,4) + "-" + RIGHT("0" + 
SUBSTRING(Date_Of_Birth,1,FINDSTRING(Date_Of_Birth,"/",1) - 1),2) + "-" + RIGHT("0" + 
SUBSTRING(Date_Of_Birth,FINDSTRING(Date_Of_Birth,"/",1) + 1,FINDSTRING(Date_Of_Birth,"/",2) - 
FINDSTRING(Date_Of_Birth,"/",1)),2))

I used the one on todds blog (http://toddmcdermid.blogspot.co.uk/2008/11/converting-strings-to-dates-in-derived.html) but it seems not to work for me for some reason. Can anyone explain how I can go about this

Upvotes: 1

Views: 1947

Answers (1)

Blindsniper
Blindsniper

Reputation: 56

Maybe write the .NET code in the script task to convert the date format is the better idea:

    Dim dateStr As String = "23/12/2001"
    Dim result As DateTime

    If DateTime.TryParseExact(dateStr, "dd/MM/yyyy", Nothing, Globalization.DateTimeStyles.None, result) Then
        MsgBox(result.ToString("yyyy-MM-dd"))
    End If

Upvotes: 1

Related Questions