How do I get the month and day with leading 0's in SQL? (e.g. 9 => 09)

sql, t-sql

Solution

For SQL Server 2012 and up , with leading zeroes:

 SELECT FORMAT(GETDATE(),'MM') 

without:

SELECT    MONTH(GETDATE())

Problem

``` DECLARE @day CHAR(2) SET @day = DATEPART(DAY, GETDATE()) PRINT @day ``` If today was the 9th of December, the above would print "9". I want to print "09". How do I go about doing this?

Original source