How can I get current month in number in SQL Server?
Means for January I want 1 and for December I want 12.
Use the MONTH() function to retrieve a month from a date/datetime/timestamp column in MySQL. This function takes only one argument – either an expression which returns a date/datetime/ timestamp value or the name of a date/datetime/timestamp column. (In our example, we use the start_date column of date data type).
In SQL Server, you can use the MONTH() function to convert a month name to its corresponding number.
To get the previous month in SQL Server, subtract one month from today's date and then extract the month from the date. First, use CURRENT_TIMESTAMP to get today's date. Then, subtract 1 month from the current date using the DATEADD function: use MONTH as the date part with -1 as the parameter.
How about this:
SELECT MONTH(GETDATE())
This will return values 1 through 12 depending on the month.
See the relevant MSDN documentation for details - that entire documentation site is freely available for consultation by everyone - use it!
You may try like this:
SELECT MONTH(datecolumn) from table
Also check for more details about MONTH
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