The DAY, MONTH, YEAR functions can be used to extract the day, month, and year from a date. These features are most commonly used in reporting and data analysis.
Examples:
The following functions were run on February 20, 2022, and the results are based on that date.
SELECT DAY(GETDATE());
Returns: 20
SELECT DAY(‘2022-02-28’);
Returns: 28
SELECT MONTH(GETDATE());
Returns: 2
SELECT MONTH(‘2022-02-28’);
Returns: 2
SELECT YEAR(GETDATE());
Returns: 2022
SELECT YEAR(‘2022-02-28’);
Returns: 2022
2 comments