How can I get the month number in sql? I use the following code but it returns the month name.
SELECT DATENAME(mm, GETDATE())
How can I get the month number in sql? I use the following code but it returns the month name.
SELECT DATENAME(mm, GETDATE())
This will return with two char in case of Jan-Sep:
Use the month function -
SELECT MONTH(GETDATE())
You can also use this to pad the month number
You want
DATEPART
:Use datepart function with m extension.
Try the below: