时间:2021-07-01 10:21:17 帮助过:12人阅读
使用Convert()函数:
SELECT CONVERT(varchar(100), GETDATE(), 0) 05 9 2011 9:12AM
SELECT CONVERT(varchar(100), GETDATE(), 1) 05/09/11
SELECT CONVERT(varchar(100), GETDATE(), 2) 11.05.09
SELECT CONVERT(varchar(100), GETDATE(), 3) 09/05/11
SELECT CONVERT(varchar(100), GETDATE(), 4) 09.05.11
SELECT CONVERT(varchar(100), GETDATE(), 5) 09-05-11
SELECT CONVERT(varchar(100), GETDATE(), 6) 09 05 11
SELECT CONVERT(varchar(100), GETDATE(), 7) 05 09, 11
SELECT CONVERT(varchar(100), GETDATE(), 8) 09:13:14
SELECT CONVERT(varchar(100), GETDATE(), 9) 05 9 2011 9:13:14:670AM
SELECT CONVERT(varchar(100), GETDATE(), 10) 05-09-11
SELECT CONVERT(varchar(100), GETDATE(), 11) 11/05/09
SELECT CONVERT(varchar(100), GETDATE(), 12) 110509
SELECT CONVERT(varchar(100), GETDATE(), 13) 09 05 2011 09:13:14:670
SELECT CONVERT(varchar(100), GETDATE(), 14) 09:13:14:670
SELECT CONVERT(varchar(100), GETDATE(), 20) 2011-05-09 09:13:14
SELECT CONVERT(varchar(100), GETDATE(), 21) 2011-05-09 09:13:14.670
SELECT CONVERT(varchar(100), GETDATE(), 22) 05/09/11 9:15:33 AM
SELECT CONVERT(varchar(100), GETDATE(), 23) 2011-05-09
SELECT CONVERT(varchar(100), GETDATE(), 24) 09:15:33
SELECT CONVERT(varchar(100), GETDATE(), 25) 2011-05-09 09:15:33.140
SELECT CONVERT(varchar(100), GETDATE(), 100) 05 9 2011 9:15AM
SELECT CONVERT(varchar(100), GETDATE(), 101) 05/09/2011
SELECT CONVERT(varchar(100), GETDATE(), 102) 2011.05.09
SELECT CONVERT(varchar(100), GETDATE(), 103) 09/05/2011
SELECT CONVERT(varchar(100), GETDATE(), 104) 09.05.2011
SELECT CONVERT(varchar(100), GETDATE(), 105) 09-05-2011
SELECT CONVERT(varchar(100), GETDATE(), 106) 09 05 2011
SELECT CONVERT(varchar(100), GETDATE(), 107) 05 09, 2011
SELECT CONVERT(varchar(100), GETDATE(), 108) 09:16:38
SELECT CONVERT(varchar(100), GETDATE(), 109) 05 9 2011 9:16:38:543AM
SELECT CONVERT(varchar(100), GETDATE(), 110) 05-09-2011
SELECT CONVERT(varchar(100), GETDATE(), 111) 2011/05/09
SELECT CONVERT(varchar(100), GETDATE(), 112) 20110509
SELECT CONVERT(varchar(100), GETDATE(), 113) 09 05 2011 09:17:19:857
SELECT CONVERT(varchar(100), GETDATE(), 114) 09:17:19:857
SELECT CONVERT(varchar(100), GETDATE(), 120) 2011-05-09 09:17:19
SELECT CONVERT(varchar(100), GETDATE(), 121) 2011-05-09 09:17:19.857
SELECT CONVERT(varchar(100), GETDATE(), 126) 2011-05-09T09:17:19.857
SELECT CONVERT(varchar(100), GETDATE(), 130) 6 ????? ??????? 1432 9:17:19:857AM
SELECT CONVERT(varchar(100), GETDATE(), 131) 6/06/1432 9:17:19:857AM
给为空的字段赋值
UPDATE TableName set colName=‘‘ where colName is null
用sql语句把时间a与b的差加到c上赋值给d
CONVERT(varchar(100), dateadd(s,(datediff(s,a,‘1970-01-01 00:00:00‘)-datediff(s,b,‘1970-01-01 00:00:00‘)+datediff(s,c,‘1970-01-01 00:00:00‘)),‘1970-01-01 00:00:00‘),20)
CONVERT(varchar(100),date,20)
dateadd(s,date1,date2)
datediff(s,date1,date2)
思路为把abc都转化成时间戳,得到的值也是时间戳。后把时间戳再转化成时间就可以了
SQL Server 取日期时间部分
标签:ted tab date() 1.0 table col lse 组成 end