Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get the current month number in SQL Server, 1 for january, 12 for december

Tags:

How can I get current month in number in SQL Server?

Means for January I want 1 and for December I want 12.

like image 347
AnandMeena Avatar asked Oct 19 '13 11:10

AnandMeena


People also ask

How do I find a specific month of data in SQL?

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).

How do I get month name to month number in SQL Server?

In SQL Server, you can use the MONTH() function to convert a month name to its corresponding number.

How get current month and last month in SQL?

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.


2 Answers

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!

like image 131
marc_s Avatar answered Nov 09 '22 07:11

marc_s


You may try like this:

SELECT MONTH(datecolumn) from table 

Also check for more details about MONTH

like image 36
Rahul Tripathi Avatar answered Nov 09 '22 05:11

Rahul Tripathi