I have an integer column "Month" I would like to get 2 digit number for month.
This is what I have tried: DATEPART(mm, @Date)
It returns one digit for months January to September I am using SQL Server 2008
Anyone has suggestion?
An alternative way to get a month number from an Excel date is using the TEXT function: =TEXT(A2, "m") - returns a month number without a leading zero, as 1 - 12. =TEXT(A2,"mm") - returns a month number with a leading zero, as 01 - 12.
SELECT RIGHT('0' + RTRIM(MONTH('12-31-2012')), 2);
For this, you can use LPAD() and pad a value on the left.
Function
FORMAT(date,'MM')
will do the job with two digit.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With