# 有没有更简单的方法来获得两位数的年份？

#### Is there a simpler method for getting the two digit year?

``````REPLACE((SUBSTRING(STR (Year(@Date),4),3,2)), ' ', '0')**
``````

``````DECLARE @TestVariable AS VARCHAR(100),
@Date as datetime = GetDate()
SET @TestVariable = '1234'
+ REPLACE(STR(MONTH(@Date), 2), ' ', '0')
+ REPLACE(STR(DAY(@Date), 2), ' ', '0')
+  REPLACE((SUBSTRING(STR (Year(@Date),4),3,2)), ' ', '0')

PRINT @TestVariable
``````
4 个回复

``````DECLARE @TestVariable AS VARCHAR(100) = '1234'
, @Date as datetime = GetDate()

Select @TestVariable + FORMAT(@Date, 'MMddyy')
``````

``````DECLARE @TestVariable varchar(100) = '1234',
@Date datetime = GETDATE();

SELECT @TestVariable + REPLACE(CONVERT(varchar(8),@Date, 1),'/','');
``````
``````select replace(convert(varchar(20),@date,1)'/','') --or any other you need
``````

``````set @TestVariable = '1234'
+ right('0' + cast(month(@date)      as varchar(2)), 2)
+ right('0' + cast(day(@date)        as varchar(2)), 2)
+ right('0' + cast(year(@date) % 100 as varchar(2)), 2);
``````

2 日期为两位数的年份

3 Pandas - 从日期中获取两位数的年份

4 SimpleDateFormat中的两位数年份

5 NSDateFormatter的两位数年份无效

6 PHP用两位数年份转换日期

2016-05-02 16:06:15 2 2353   php/ date
8 如何根据两位数的开始年份来计算当前学年？

9 从年份中删除前两位数字-Postgresql

10 在Ruby中将两位数年份转换为四位数年份