How can I get the month number in sql? I use the following code but it returns the month name.
SELECT DATENAME(mm, GETDATE())
The MONTH() function returns the month part for a specified date (a number from 1 to 12).
Here's how this works: First we format the date in YYYYMMDD... format truncating to keep just the 6 leftmost characters in order to keep just the YYYYMM portion, and then append '01' as the month - and voila! you have the first day of the current month.
MySQL MONTHNAME() Function The MONTHNAME() function returns the name of the month for a given date.
Use datepart function with m extension.
SELECT DATEPART(m, getdate())
Use the month function - SELECT MONTH(GETDATE())
Use Datepart:
DATEPART(mm,getdate());
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