1,设计积分系统,要设置积分过期,要求,积分在获取之日起 一年后失效,且 格式应该为 “####-##-## 00:00:00”
实现代码
select dateadd(year,1,CONVERT(varchar(100),getdate(),23))
CONVERT(varchar(100),getdate(),23)
这一步 获取不带时分秒的年月日 格式:2014-07-08
然后,年份加1 即可。
2,提取年份后两位 +月份+日+‘T’+orderid
组成一个字符串
提取年月日:
year (getdate()) ,month(getdate()),day(getdate())
得到的结果都是整形,不能用”+“连接。只能转换成字符串才能连接
提取年份后两位
right(year(getdate()),2)
连接后得:
convert(varchar(2),right(year(getdate()),2))+convert(varchar(2),month(getdate()))+convert(varchar(2),day(getdate()))
最后连接
+'T'+@orderid
完整测试代码:
declare @ot datetime
declare @orderid int
set @orderid=20051024
set @ot=getdate()
select convert(varchar(2),right(year(@ot),2))+convert(varchar(2),month(@ot))
+convert(varchar(2),day(@ot))+'T'+convert(varchar(10),@orderid)