Home Forums SQL Server 2012 SQL Server 2012 - T-SQL Conversion of Date from legacy systems with 7 and 6 digit format to DD/MM/YYYY format RE: Conversion of Date from legacy systems with 7 and 6 digit format to DD/MM/YYYY format

  • Surely you can simply

    DECLARE @oldDate varchar(10) = '0980423'

    SELECT

    DATEFROMPARTS

    (

    convert(Int,LEFT(@oldDate,3))+1900 --Year

    ,Substring(@oldDate,4,2)--Month

    ,Right(@oldDate,2)--Day

    )

    The output is a DATE datatype, this obviously assumes the data is correctly formatted and clean.

    As others have said if you are converting the field to a new DB you might as well start changing the datatypes as well where necessary.

    EDIT : I didn't see Steves suggestion until just now.

    _________________________________________________________________________
    SSC Guide to Posting and Best Practices