取當前時間值 getdate()
比較兩個時間的差 datediff()
select top 1000 [序號]
,[生效日期]
,[失效日期]
,datediff(day,失效日期, getdate()) as 日
,datediff(year,失效日期, getdate()) as 年1
,datediff(day,gd_zj.失效日期, getdate() )/365 as 年
from [dqdata].[dbo].[gd_zj]
轉換函式 convert ( data_type [ ( length ) ] , expression [ , style ] )
select convert(char(10),getdate(),120) //從日期時間值提取出日期
select convert(varchar(100), getdate(), 0) –jul 24 2018 2:44pm
select convert(varchar(100), getdate(), 1) –07/24/18
select convert(varchar(100), getdate(), 2) –18.07.24
select convert(varchar(100), getdate(), 3) –24/07/18
select convert(varchar(100), getdate(), 4) –24.07.18
select convert(varchar(100), getdate(), 5) –24-07-18
select convert(varchar(100), getdate(), 6) –24 jul 18
select convert(varchar(100), getdate(), 7) –jul 24, 18
select convert(varchar(100), getdate(), 8) –14:47:03
select convert(varchar(100), getdate(), 9) –jul 24 2018 2:47:27:863pm
select convert(varchar(100), getdate(), 10) –07-24-18
select convert(varchar(100), getdate(), 11) –18/07/24
select convert(varchar(100), getdate(), 12) –180724
select convert(varchar(100), getdate(), 13) –24 jul 2018 14:48:52:453
select convert(varchar(100), getdate(), 14) –14:49:08:250
select convert(varchar(100), getdate(), 20) –2018-07-24 14:49:23
select convert(varchar(100), getdate(), 21) –2018-07-24 14:49:43.837
select convert(varchar(100), getdate(), 22) –07/24/18 2:50:02 pm
select convert(varchar(100), getdate(), 23) –2018-07-24
select convert(varchar(100), getdate(), 24) –14:50:50
select convert(varchar(100), getdate(), 25) –2018-07-24 14:51:05.733
select convert(varchar(100), getdate(), 100) –jul 24 2018 2:51pm
select convert(varchar(100), getdate(), 101) –07/24/2018
select convert(varchar(100), getdate(), 102) –2018.07.24
select convert(varchar(100), getdate(), 103) –24/07/2018
select convert(varchar(100), getdate(), 104) –24.07.2018
select convert(varchar(100), getdate(), 105) –24-07-2018
select convert(varchar(100), getdate(), 106) –24 jul 2018
select convert(varchar(100), getdate(), 107) –jul 24, 2018
select convert(varchar(100), getdate(), 108) –14:53:27
select convert(varchar(100), getdate(), 109) –jul 24 2018 2:53:45:740pm
select convert(varchar(100), getdate(), 110) –07-24-2018
select convert(varchar(100), getdate(), 111) –2018/07/24
select convert(varchar(100), getdate(), 112) –20180724
select convert(varchar(100), getdate(), 113) –24 jul 2018 14:55:14:070
select convert(varchar(100), getdate(), 114) –14:56:00:610
select convert(varchar(100), getdate(), 120) –2018-07-24 14:56:14
select convert(varchar(100), getdate(), 121) –2018-07-24 14:56:30.440
select convert(varchar(100), getdate(), 126) –2018-07-24t14:56:50.703
select convert(varchar(100), getdate(), 130) –12 ?? ?????? 1439 2:57:07:070pm
select convert(varchar(100), getdate(), 131) –12/11/1439 2:57:32:280pm
sql中日期時間相關函式
增加日期 date add adddate select date add 2020 11 04 interval 31day date 輸出 2020 12 05 select adddate 2020 11 04 31 date 輸出 2020 12 05計算兩個時間差 timestampdif...
sql語句,日期時間相關
修改時間段,將此時間段內資料的時間增加乙個月插入到表裡 壩頂沉降 insert into dtjc bd bd sbbh,bd y,bd time select bd sbbh,bd y,date add bd time,interval 1month from dtjc bd c where c....
SQL時間相關 SQL日期,時間比較
sql server 中時間比較 例子 select count from table where datediff second 2004 09 18 00 00 18 2004 09 18 00 00 19 0 說明select datediff day,time1 time2 對應示例語句如下...