Format() function doesn't work?

Use Convert function instead. Example:

select convert(varchar(5), GETDATE(), 126) + convert(varchar(5), GETDATE(), 105)

That's because FORMAT() is not a built-in function in SQL 2005. You need to use the CONVERT() function:

SELECT
    EmpId,
    EmpName,
    REPLACE(CONVERT(VARCHAR(10), EmpJoinDate, 102), '.', '-') AS date
FROM
    Employee

A few caveats though... "date" is a reserved word I believe, so I wouldn't suggest using that, even as a column alias. Also, the above actually gives YYYY-MM-DD. YYYY-DD-MM is pretty rare I believe. If you truly want that you'll need to either concatenate things together yourself with the DATEPART and CAST functions or concatenate things using SUBSTRING with CONVERT.

Do a search on CONVERT and you should be able to find all of the various formats supported. The one that I used above (102) is for YYYY.MM.DD, so I did a replace to give the hyphens instead.


According to MSDN documentation, http://msdn.microsoft.com/en-us/library/hh213505(SQL.110).aspx, it is a built-in function. I am assuming it has not been implemented.