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

  • I would still use an arithmetic formula instead of string manipulation.

    CREATE FUNCTION ConvertLegacyIntToDate

    (

    @LegacyDate int

    )

    RETURNS TABLE WITH SCHEMABINDING AS

    RETURN

    SELECT CAST( CAST( 19000000 + oldDate AS CHAR(8)) AS date) as NewDate

    Or I would just use the formula each time. As Sean mentioned, scalar functions are bad for performance and can be replaced by inline table valued functions, but it seems overkill this time, IMHO.

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2