T-SQL Tutorial

Get month from date


Get month from date

To get month from an specified date uses functions DATEPART or MONTH.
The DATEPART function returns an int data type that representing the specified datepart of the date.
The MONTH function returns an int data type that represents the month of the date. MONTH returns the same value as DATEPART.

DATEPART

DATEPART ( datepart , date )

MONTH

MONTH ( date )

Current month

Get current month from date.

SELECT DATEPART(month, GETDATE());
Result: 1

SELECT MONTH(GETDATE());
Result: 1





Get month

Get month from date.

SELECT DATEPART(month, '21-DEC-2021');
Result: 12

SELECT DATEPART(month, '10/28/2021');
Result: 10

SELECT MONTH('21-DEC-2021');
Result: 12

SELECT MONTH('10/28/2021');
Result: 10

SQL Server DATEPART function
SQL Server MONTH function