datetime conversion

  • I need to convert following dates into datetime. consider year 2009

    Here is input

    20Jul 15:46:1

    22Jul 06:21:8

  • The following code works for the examples you posted:

    DECLARE @Input TABLE ([Date] VARCHAR(14))

    INSERT INTO @Input

    SELECT '20Jul 15:46:1' UNION ALL

    SELECT '22Jul 06:21:8'

    SELECT CONVERT(DATETIME, SUBSTRING([Date],1,2) + ' ' + SUBSTRING([Date],3, LEN([Date]) - 2) + ' 2009') FROM @Input

  • Another option SELECT Convert(Datetime, Replace('20Jul 15:46:1', ' ', '2009 '))

    Drew

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply