Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get 2 Digit Number For The Month

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?

like image 671
Adam Avatar asked Feb 20 '13 09:02

Adam


People also ask

How do I get the 2 digit month in Excel?

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.

How can I get 2 digit month in SQL?

SELECT RIGHT('0' + RTRIM(MONTH('12-31-2012')), 2);

How do you get a two digit number in SQL?

For this, you can use LPAD() and pad a value on the left.


1 Answers

Function

FORMAT(date,'MM')  

will do the job with two digit.

like image 146
user3829053 Avatar answered Oct 01 '22 11:10

user3829053