How do I select month with leading zeroes in T-SQL

January 9, 2013

SQL Server doesn’t provide leading zeroes in a month selection, so you’ll have to add them yourself. The easiest way to do this is probably to create a two- or three-digit string and taking a RIGHT() substring to select the rightmost two digits.

Example:

RIGHT('0' + CONVERT(VARCHAR(2), MONTH(getdate()))

Author

Stay in Touch!

Stay in Touch!
Solutions Architecture

browse through our blog articles

Blog Archive