sql server 日期,時間獲取

2021-09-22 12:23:31 字數 1529 閱讀 2784

select getdate();--獲取當前日期

select convert(varchar,getdate(),120) --獲取當前日期(格式化)

select datename(yyyy,getdate()) --年

select datename(year,getdate()) --年

select datepart(yyyy,getdate()) --年

select datepart(year,getdate()) --年

select year(start_date) from ty_org;--年

select datename(mm,getdate()) --月 05

select datename(month,getdate()) --月 05

select datepart(mm,getdate()) --月 5

select datepart(month,getdate()) --月 5

select month(start_date) from ty_org; --月 5

select datename(day,getdate()) --日 23

select datename(d,getdate()) --日 23

select datename(dd,getdate()) --日 23

select datepart(d,getdate()) --日 23

select datepart(dd,getdate()) --日 23 

select datepart(day,getdate()) --日 23

select day(getdate()) -- 日 23

select convert(varchar(6),getdate(),112) --年月 201804

select convert(varchar(7),getdate(),120) --年月 2018-04

select convert(varchar(8),getdate(),112) --獲取當前年月日 20180423

select convert(varchar(10),getdate(),120);--獲取當前年月日 yyyy-mm-dd

select convert(varchar,getdate(),20)  --2018-04-23 14:44:22

select convert(varchar,getdate(),23)  --2018-04-23

select convert(varchar,getdate(),24)  --14:44:22

select convert(varchar,getdate(),102) --2018.04.23

select convert(varchar,getdate(),111) --2018/04/23

select convert(datetime,'2018-04-23',20) --2018-04-23 00:00:00.000

select convert(date,'2018-04-23',20) --2018-04-23

SQLserver 獲取時間

1.獲取當前日期 selectgetdate 格式化 selectconvert varchar,getdate 120 2017 05 12 16 33 10 2.獲取當前年 2017 selectdatename yyyy,getdate 2017 selectdatename year,get...

sql server日期時間函式

2.dateadd 在向指定日期加上一段時間的基礎上,返回新的 datetime 值 例如 向日期加上2天 select dateadd day,2,2004 10 15 返回 2004 10 17 00 00 00.000 3.datediff 返回跨兩個指定日期的日期和時間邊界數。select ...

sql server日期時間函式

sql server日期時間函式 sql server中的日期與時間函式 1.當前系統日期 時間 select getdate 2.dateadd 在向指定日期加上一段時間的基礎上,返回新的 datetime 值 例如 向日期加上2天 select dateadd day,2,2004 10 15 ...