If you used databases like Oracle or Teradata, you can be suprised that very popular function like 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.
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:
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 or share this post on your Facebook, Twitter, LinkedIn or another social media webpage.
Thanks in advanced!