• daviesj (3/23/2012)


    interesting article, thanks., but what about just using some variation on

    select replace(convert(varchar(30), getdate(), 103, '/', '\')

    ( i don't have SQL server in front of me to check I've used the right format - I can't recall them all, for which reason i have a couple of UDFs like this at work...)

    Using some string manipulation on built-in CONVERT styles is definitely one of the options, given that you wrap it inside a UDF (you don't want to write all that code every time you need to format, do you?).

    Unfortunately, it could be quite easy to implement for a specific format and nearly impossible for others.

    Moreover, from a performance standpoint, a custom CLR function outperforms all the other methods, REPLACE and variations included. If you really have to format dates, I would strongly recommend using that.

    -- Gianluca Sartori