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?
这对你有用
select Right(Year(getDate())+ 1,2)
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.
SELECT RIGHT(CONVERT(VARCHAR(8), GETDATE(), 1),2) as YEAR
你可以在 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!
select CAST( DAY(GETDATE()) as varchar(10))+'/'+CAST( month(GETDATE()) as varchar(10))+'/' +cast(right(year(getDate()),2) as varchar)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.