首页 > 其他 > 详细

时间日期函数 类型转换

时间:2015-11-22 21:49:03      阅读:304      评论:0      收藏:0      [点我收藏+]

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!