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
-
7and do the
+ 1
before the% 100
, if you wantxx99
to yield 0 rather than 100– AakashMSep 14, 2010 at 17:01
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.
-
@VeryColdAir The original question was ` get the current 2-digit year and increment by one`.– wp78deJul 20, 2022 at 15:01
You can try this in sql server
SELECT FORMAT(GETDATE(), 'yy')
-
1This does not answer the OP's question of getting the current year + 1.– wp78deJul 20, 2022 at 15:02
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!
select CAST( DAY(GETDATE()) as varchar(10))+'/'+CAST( month(GETDATE()) as varchar(10))+'/' +cast(right(year(getDate()),2) as varchar)