DAY, MONTH, YEAR functions in SQL Server

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

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s