Nicolas Santisteban Nicolas Santisteban - 18 days ago 9
SQL Question

How to get the day with zeros in SQL Server

I want to know how I can get the day from a datetime column in sql server, I'm using the funcion DAY but it's giving me the day without the zeros for example:

Column: 2014-08-20 10:28:20.6470000
SELECT DAY(COLUMN) FROM TABLE = 8


What I expect is something like:

SELECT DAY(COLUMN) FROM TABLE = 08


Thanks

Answer

Another option is the Format() if 2012+

Select Format(COLUMN,'dd')

I should add, Format() is not know for its performance, but it does have some nice functionality.