SQL Server Tutorial SQL Server Advanced SQL Server Database SQL Server References

SQL Server MONTH() Function



The SQL Server (Transact-SQL) MONTH() function returns the month for the specified date. It can be between 1 to 12.

Syntax

MONTH(date)

Parameters

date Required. Specify a date from which to extract the month.

Return Value

Returns the month part of the given date value.

Example 1:

The example below shows the usage of MONTH() function.

SELECT MONTH('2018-08-18');
Result: 8

SELECT MONTH('2018-08-18 10:38:42');
Result: 8

SELECT MONTH('2018-08-18 10:38:42.0000004');
Result: 8

SELECT MONTH('2014-10-25');
Result: 10

Example 2:

Consider a database table called Orders with the following records:

OrderQuantityPriceOrderTime
1001.582017-08-18 10:38:42
1201.612018-03-23 07:14:16
1251.782018-09-12 05:25:56
501.802019-01-16 11:52:05
2001.722020-02-06 09:31:34

The statement given below can be used to get the month portion of records of column OrderTime:

SELECT *, MONTH(OrderTime) AS MONTH_Value FROM Orders;

This will produce the result as shown below:

OrderQuantityPriceOrderTimeMONTH_Value
1001.582017-08-18 10:38:428
1201.612018-03-23 07:14:163
1251.782018-09-12 05:25:569
501.802019-01-16 11:52:051
2001.722020-02-06 09:31:342

❮ SQL Server Functions