SQL SEVER时间与字符串转换
1.时间转换成字符串形式
不带世纪位数的转换代码
SELECT CONVERT(varchar(100), GETDATE(), 0) AS Style0 10 25 2019 9:14AM SELECT CONVERT(varchar(100), GETDATE(), 1) AS Style1 10/25/19 SELECT CONVERT(varchar(100), GETDATE(), 2) AS Style2 19.10.25 SELECT CONVERT(varchar(100), GETDATE(), 3) AS Style3 25/10/19 SELECT CONVERT(varchar(100), GETDATE(), 4) AS Style4 25.10.19 SELECT CONVERT(varchar(100), GETDATE(), 5) AS Style5 25-10-19 SELECT CONVERT(varchar(100), GETDATE(), 6) AS Style6 25 10 19 SELECT CONVERT(varchar(100), GETDATE(), 7) AS Style7 10 25, 19 SELECT CONVERT(varchar(100), GETDATE(), 8) AS Style8 09:15:25 SELECT CONVERT(varchar(100), GETDATE(), 9) AS Style9 10 25 2019 9:15:32:263AM SELECT CONVERT(varchar(100), GETDATE(), 10) AS Style10 10-25-19 SELECT CONVERT(varchar(100), GETDATE(), 11) AS Style11 19/10/25 SELECT CONVERT(varchar(100), GETDATE(), 12) AS Style12 191025 SELECT CONVERT(varchar(100), GETDATE(), 13) AS Style13 25 10 2019 09:16:32:433 SELECT CONVERT(varchar(100), GETDATE(), 14) AS Style14 09:17:05:897 SELECT CONVERT(varchar(100), GETDATE(), 20) AS Style21 2019-10-25 09:16:59 SELECT CONVERT(varchar(100), GETDATE(), 21) AS Style21 2019-10-25 09:17:16.317 SELECT CONVERT(varchar(100), GETDATE(), 22) AS Style22 10/25/19 9:17:21 AM SELECT CONVERT(varchar(100), GETDATE(), 23) AS Style23 2019-10-25 SELECT CONVERT(varchar(100), GETDATE(), 24) AS Style24 09:17:35 SELECT CONVERT(varchar(100), GETDATE(), 25) AS Style25 2019-10-25 09:17:40.997
带世纪位数的转换
SELECT CONVERT(varchar(100), GETDATE(), 100) AS Style100 10 25 2019 9:21AM SELECT CONVERT(varchar(100), GETDATE(), 101) AS Style101 10/25/2019 SELECT CONVERT(varchar(100), GETDATE(), 102) AS Style102 2019.10.25 SELECT CONVERT(varchar(100), GETDATE(), 103) AS Style103 25/10/2019 SELECT CONVERT(varchar(100), GETDATE(), 104) AS Style104 25.10.2019 SELECT CONVERT(varchar(100), GETDATE(), 105) AS Style105 25-10-2019 SELECT CONVERT(varchar(100), GETDATE(), 106) AS Style106 25 10 2019 SELECT CONVERT(varchar(100), GETDATE(), 107) AS Style107 10 25, 2019 SELECT CONVERT(varchar(100), GETDATE(), 108) AS Style108 09:22:45 SELECT CONVERT(varchar(100), GETDATE(), 109) AS Style109 10 25 2019 9:22:50:860AM SELECT CONVERT(varchar(100), GETDATE(), 110) AS Style110 10-25-2019 SELECT CONVERT(varchar(100), GETDATE(), 111) AS Style111 2019/10/25 SELECT CONVERT(varchar(100), GETDATE(), 112) AS Style112 20191025 SELECT CONVERT(varchar(100), GETDATE(), 113) AS Style113 25 10 2019 09:23:15:680 SELECT CONVERT(varchar(100), GETDATE(), 114) AS Style114 09:23:21:843 SELECT CONVERT(varchar(100), GETDATE(), 120) AS Style121 2019-10-25 09:23:27 SELECT CONVERT(varchar(100), GETDATE(), 121) AS Style121 2019-10-25 09:23:33.463 SELECT CONVERT(varchar(100), GETDATE(), 126) AS Style126 2019-10-25T09:23:39.797 SELECT CONVERT(varchar(100), GETDATE(), 127) AS Style127 2019-10-25T09:23:44.977 SELECT CONVERT(varchar(100), GETDATE(), 130) AS Style130 26 ??? 1441 9:23:51:497AM SELECT CONVERT(varchar(100), GETDATE(), 131) AS Style131 26/02/1441 9:24:04:150AM
2.字符串转换成时间
SELECT CONVERT(datetime , '2019-10-25') AS Style111 2019-10-25 00:00:00.000