Home Forums SQL Server 2008 T-SQL (SS2K8) Using CAST or CONVERT to change data from string to datetime RE: Using CAST or CONVERT to change data from string to datetime

  • CONVERT takes a style parameter which can be used to shape the output of a date-datatype to string-datatype conversion - which is the usage that most folks are familiar with. It works for input too, describing the shape of a text string for a string-datatype to date-datatype conversion.

    Your data corresponds to style 12: yymmdd. Hence, all you need to convert your data is this:

    CONVERT(DATE,LEFT(MyField,6),12).

    “Write the query the simplest way. If through testing it becomes clear that the performance is inadequate, consider alternative query forms.” - Gail Shaw

    For fast, accurate and documented assistance in answering your questions, please read this article.
    Understanding and using APPLY, (I) and (II) Paul White
    Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden