declare @datetime datetime = Current_Timestamp
,@date date = Current_Timestamp
,@time time = Current_Timestamp
select @datetime --2018-06-08 09:01:10.440
select @date --2018-06-08
select @time --09:01:10.4400000
-----------DATEADD() 函数在日期中添加或减去指定的时间间隔。---------------------
select Dateadd(d,1,'2018-01-01 00:00:00.000')--2018-01-02 00:00:00.000
------------DATEDIFF() 函数返回两个日期之间的时间。------------------------------
select datediff(day,Convert(date,'20181101') , Convert(date,'20181028')) --(-4)
select Datediff(d,'2018-01-01','2018-01-02') --1
--DateName 返回字符串类型
SELECT GETDATE() AS 当前日期,
DATENAME(YEAR, GETDATE()) AS 年,
DATENAME(MONTH, GETDATE()) AS 月,
DATENAME(DAY, GETDATE()) AS 日,
DATENAME(quarter, GETDATE()) AS 季度,
DATENAME(dayofyear, GETDATE()) AS 一年中的第多少天,
DATENAME(dw, GETDATE()) AS 星期,
DATENAME(week, GETDATE()) AS 周数,
DATENAME(hour, GETDATE()) AS 时,
DATENAME(minute, GETDATE()) AS 分,
DATENAME(second, GETDATE()) AS 秒,
DATENAME(millisecond,GETDATE()) AS 毫秒
select Datepart(yy,GETDATE())--返回数值类型
select Isdate('2018-01-32') --判断字符串是否是日期,是1,否0
select YEAR(GETDATE()) as 年,Month(GETDATE()) as 月,Day(GETDATE()) as 日 --返回数值类型
分享题目:Sql日期类型
网页网址:
http://chengdu.cdxwcx.cn/article/ggcdod.html