Skip to content
Advertisement

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?

Advertisement

Answer

there are different ways of doing it

  • Using RTRIM and specifing the range:

like

  • Using Substring to just extract the month part after converting the date into text

like

see Fiddle

There may be other ways to get this.

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement