sql convert函数使用小结
sql convert函数使用方法小结整理的比较全了,需要的朋友可以参考下。
CONVERT(data_type,expression[,style])
convert(varchar(10),字段名,转换格式)
说明:
此样式一般在时间类型(datetime,smalldatetime)与字符串类型(nchar,nvarchar,char,varchar)
相互转换的时候才用到.
语句 结果
SELECT CONVERT(varchar(100), GETDATE(), 0) 07 15 2009 4:06PM
SELECT CONVERT(varchar(100), GETDATE(), 1) 07/15/09
SELECT CONVERT(varchar(100), GETDATE(), 2) 09.07.15
SELECT CONVERT(varchar(100), GETDATE(), 3) 15/07/09
SELECT CONVERT(varchar(100), GETDATE(), 4) 15.07.09
SELECT CONVERT(varchar(100), GETDATE(), 5) 15-07-09
SELECT CONVERT(varchar(100), GETDATE(), 6) 15 07 09
SELECT CONVERT(varchar(100), GETDATE(), 7) 07 15, 09
SELECT CONVERT(varchar(100), GETDATE(), 8) 16:06:26
SELECT CONVERT(varchar(100), GETDATE(), 9) 07 15 2009 4:06:26:513PM
SELECT CONVERT(varchar(100), GETDATE(), 10) 07-15-09
SELECT CONVERT(varchar(100), GETDATE(), 11) 09/07/15
SELECT CONVERT(varchar(100), GETDATE(), 12) 090715
SELECT CONVERT(varchar(100), GETDATE(), 13) 15 07 2009 16:06:26:513
SELECT CONVERT(varchar(100), GETDATE(), 14) 16:06:26:513
SELECT CONVERT(varchar(100), GETDATE(), 20) 2009-07-15 16:06:26
SELECT CONVERT(varchar(100), GETDATE(), 21) 2009-07-15 16:06:26.513
SELECT CONVERT(varchar(100), GETDATE(), 22) 07/15/09 4:06:26 PM
SELECT CONVERT(varchar(100), GETDATE(), 23) 2009-07-15
SELECT CONVERT(varchar(100), GETDATE(), 24) 16:06:26
SELECT CONVERT(varchar(100), GETDATE(), 25) 2009-07-15 16:06:26.513
SELECT CONVERT(varchar(100), GETDATE(), 100) 07 15 2009 4:06PM
SELECT CONVERT(varchar(100), GETDATE(), 101) 07/15/2009
SELECT CONVERT(varchar(100), GETDATE(), 102) 2009.07.15
SELECT CONVERT(varchar(100), GETDATE(), 103) 15/07/2009
SELECT CONVERT(varchar(100), GETDATE(), 104) 15.07.2009
SELECT CONVERT(varchar(100), GETDATE(), 105) 15-07-2009
SELECT CONVERT(varchar(100), GETDATE(), 106) 15 07 2009
SELECT CONVERT(varchar(100), GETDATE(), 107) 07 15, 2009
SELECT CONVERT(varchar(100), GETDATE(), 108) 16:06:26
SELECT CONVERT(varchar(100), GETDATE(), 109) 07 15 2009 4:06:26:513PM
SELECT CONVERT(varchar(100), GETDATE(), 110) 07-15-2009
SELECT CONVERT(varchar(100), GETDATE(), 111) 2009/07/15
SELECT CONVERT(varchar(100), GETDATE(), 112) 20090715
SELECT CONVERT(varchar(100), GETDATE(), 113) 15 07 2009 16:06:26:513
SELECT CONVERT(varchar(100), GETDATE(), 114) 16:06:26:513
SELECT CONVERT(varchar(100), GETDATE(), 120) 2009-07-15 16:06:26
SELECT CONVERT(varchar(100), GETDATE(), 121) 2009-07-15 16:06:26.513
SELECT CONVERT(varchar(100), GETDATE(), 126) 2009-07-15T16:06:26.513
SELECT CONVERT(varchar(100), GETDATE(), 130) 23 ??? 1430 4:06:26:513PM
SELECT CONVERT(varchar(100), GETDATE(), 131) 23/07/1430 4:06:26:513PM
------------------------------------------------------------------------------------------------------------
3 | 103 英法 | dd/mm/yy
------------------------------------------------------------------------------------------------------------
4 | 104 德国 | dd.mm.yy
------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------
6 | 106 | dd mon yy
------------------------------------------------------------------------------------------------------------
7 | 107 | mon dd,yy
------------------------------------------------------------------------------------------------------------
8 | 108 | hh:mm:ss
------------------------------------------------------------------------------------------------------------
9 | 109 | mon dd yyyy hh:mi:ss:mmmmAM(或PM)
------------------------------------------------------------------------------------------------------------
10 | 110 美国 | mm-dd-yy
------------------------------------------------------------------------------------------------------------
11 | 111 日本 | yy/mm/dd
------------------------------------------------------------------------------------------------------------
12 | 112 ISO | yymmdd
------------------------------------------------------------------------------------------------------------
13 | 113 欧洲默认值 | dd mon yyyy hh:mi:ss:mmm(24小时制)
------------------------------------------------------------------------------------------------------------
14 | 114 | hh:mi:ss:mmm(24小时制)
------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------
21 | 121 | yyyy-mm-dd hh:mi:ss:mmm(24小时制)
------------------------------------------------------------------------------------------------------------
推荐阅读