1、时间日期函数
set datefirst 1
select @@DATEFIRST as ‘1st Day‘,DATEPART(DW,GETDATE())as ‘ToDay‘
select getdate()
select DATEADD(YEAR,2,‘2015-11-22 14:45:03.690‘)
select DATEADD(MONTH,3,‘2015-11-22 14:45:03.690‘)
select DATEADD(DAY,-4,‘2015-11-22 14:45:03.690‘)
select DATEADD(SECOND,30,‘2015-11-22 14:45:03.690‘)
select DATEDIFF(YEAR,‘2013-3-4 14:45:03.690‘,GETDATE())
select DATEDIFF(DAY,‘2013-3-4 14:45:03.690‘,GETDATE())
select DATEDIFF(DW,‘2013-3-4 14:45:03.690‘,GETDATE())
select DATEDIFF(MONTH,‘2013-3-4 14:45:03.690‘,GETDATE())
select DATEDIFF(SECOND,‘2013-3-4 14:45:03.690‘,GETDATE())
select DATEDIFF(QQ,‘2013-3-4 14:45:03.690‘,GETDATE())
declare @startday varchar(50)
set @startday=‘2010-2-2‘
select DATEDIFF(DAY,@startday,GETDATE())
declare @startday1 varchar(50)
set @startday1 = ‘2008-8-8‘
select DATEDIFF(DAY,@startday1,GETDATE())
select DATEPART(YEAR,GETDATE())
select DATEPART(MONTH ,GETDATE())
select DATEPART(QQ,GETDATE())
select YEAR(GETDATE())
select DATEPART(DW,GETDATE())
select ISDATE(‘2010-2-29‘)
2、类型转换
select cast(CAST (1.56 as decimal(18,2))as int)
select cast(CAST(‘1.78‘ as decimal(18,2)) as int)
select CAST(1.78 as int)
select CONVERT(decimal(12,2),1.82647)
原文:http://www.cnblogs.com/liujianshe1990-/p/4986597.html