Failed conversion when converting date and / or time from character string

  • Hi,

    SELECT CONVERT(VARCHAR(30), CAST (CAST('110607120921' AS VARCHAR) AS DATETIME) ,110)

    I am getting this error "Failed conversion when converting date and / or time from character string"

    I need to convert to 2011-06-07 12:09:21.000

    Please help.

  • You will need to do some string manipulation or some arithmetic on your date in order to get it into a format that can be converted. '20110607 11:11:11.111' is a format that will be recognised regardless of regional settings.

    John

  • John's right. 120 is the version of the CONVERT date statement you are after though.

    SELECT CONVERT(VARCHAR(30), CAST (CAST('20110607 12:09:21' AS VARCHAR) AS DATETIME) ,120)

    Is this just a one off thing or is the datetime stored as text in a column?

    SQL SERVER Central Forum Etiquette[/url]

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

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