在ssis中将字符串转换为Date

时间:2012-07-09 08:12:57

标签: ssis

我尝试使用ssis中的以下内容转换格式为23/12/2001到2001-12-23的日期,但我一直收到错误消息。

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))

我在todds博客上使用了一个(http://toddmcdermid.blogspot.co.uk/2008/11/converting-strings-to-dates-in-derived.html),但它似乎不适用于我某些原因。任何人都可以解释我如何解决这个问题

1 个答案:

答案 0 :(得分:1)

也许在脚本任务中编写.NET代码来转换日期格式是更好的主意:

    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
相关问题