Convert DD-Mon-YYYY to DD/MM/YYYY

  • I need to convert dt_of_birth [varchar] (15) which is in the format DD-Mon-YYYY to DD/MM/YYYY dt_of _birth is specified in different table and the conversion had to be done and stored in another table which has the same column name as dt_of_birth..

    Please help me

  • If I understand your request correctly, this may be helpful to you

    CREATE TABLE #Dob(birth VARCHAR(15))

    INSERT INTO #Dob

    SELECT '24-10-2012' UNION ALL

    SELECT '01-01-2011'

    SELECT birth AS 'Input',

    REPLACE(birth,'-','/')AS 'Converted' FROM #Dob

    Results:

    Input Converted

    24-10-201224/10/2012

    01-01-201101/01/2011

    If everything seems to be going well, you have obviously overlooked something.

    Ron

    Please help us, help you -before posting a question please read[/url]
    Before posting a performance problem please read[/url]

  • Wasn't sure about the input format, especially the "-Mon-" segment. Maybe...

    DECLARE @Dob TABLE (birth VARCHAR(15))

    INSERT INTO @Dob

    SELECT '24-Oct-2012'

    UNION ALL

    SELECT '01-Jan-2011'

    SELECT birth AS 'Input'

    , CONVERT(VARCHAR(15), CAST(birth AS DATETIME), 103) AS 'Converted'

    FROM @Dob

    Input Converted

    24-Oct-201224/10/2012

    01-Jan-201101/01/2011

    (But of course you know you should never store dates as strings, right?)

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

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