Get the 2 digit year in T-SQL

Viewed 89182

I need to get the current 2 digit year and increment by one. So the current number I'm looking for should be 11. How?

7 Answers

For SQL Server 2012 and above, I'd suggest using FORMAT(@DATE, 'yy'):

SELECT FORMAT(DATEADD(year, 1, GETDATE()), 'yy')

Format offers a cleaner, more readable solution. Thus, less guesswork, and a better maintainability.

You can try this in sql server

SELECT FORMAT(GETDATE(), 'yy')

If you are always going to be using GetDate() why not just do something like this:

Select (Year(GetDate()) - 2000) + 1

Dang people. Always making things so complicated. It's not like you are going to be living for another 1000 years!

Related