You are currently viewing SQL Server Extract Year Month Or Day From DATE Data Type? – 2 simple and useful queries!
Photo by rafzin p on Unsplash
Could You Please Share This Post? I Appreciate It And Thank YOU! :) Have A Nice Day!
4.9
(751)

If you used databases like Oracle or Teradata, you can be surprised that very popular function like [ SQL Server extract year month or day from date ] extract(year from date) not work for Microsoft’s databases. In this post I show you how to extract only a day, month or year from Microsoft SQL Server or Azure SQL Database. The both of these databases use Transact-SQL language.

SQL Server Extract Year Month Or Day From DATE Data Type

To extract only YEAR, you can use function:

YEAR( your_date ) 

It doesn’t matter if you put attribute with date data type or text in appopriate format:

e.g.:

SELECT YEAR(LOAD_DATE) FROM CUSTOMER;

SELECT YEAR('20191218');

Extract MONTH Or DAY In SQL Server

Analogously, for extract MONTH and DAY you can use:

MONTH ( your_date ) 
DAY ( your_date )
Could You Please Share This Post? 
I appreciate It And Thank YOU! :)
Have A Nice Day!

BigData-ETL: image 7YOU MIGHT ALSO LIKE

How useful was this post?

Click on a star to rate it!

Average rating 4.9 / 5. Vote count: 751

No votes so far! Be the first to rate this post.

As you found this post useful...

Follow us on social media!

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?