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. (Select Year Sql Server)
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');
Analogously, for extract MONTH and DAY you can use:
MONTH ( your_date ) DAY ( your_date )
If you enjoyed this post please add the comment below and share this post on your Facebook, Twitter, LinkedIn or another social media webpage.
Thanks in advanced!