SQLserver中用convert函數(shù)轉(zhuǎn)換日期格式的方法
發(fā)布日期:2022-01-07 09:14 | 文章來(lái)源:源碼中國(guó)
例如:
select getdate() 整理了一下SQL Server里面可能經(jīng)常會(huì)用到的日期格式轉(zhuǎn)換方法: 舉例如下:
select CONVERT(varchar, getdate(), 120 )
2004-09-12 11:06:08
select replace(replace(replace(CONVERT(varchar, getdate(), 120 ),'-',''),' ',''),':','')
20040912110608
select CONVERT(varchar(12) , getdate(), 111 )
2004/09/12
select CONVERT(varchar(12) , getdate(), 112 )
20040912
select CONVERT(varchar(12) , getdate(), 102 )
2004.09.12
select CONVERT(varchar(12) , getdate(), 101 )
09/12/2004
select CONVERT(varchar(12) , getdate(), 103 )
12/09/2004
select CONVERT(varchar(12) , getdate(), 104 )
12.09.2004
select CONVERT(varchar(12) , getdate(), 105 )
12-09-2004
select CONVERT(varchar(12) , getdate(), 106 )
12 09 2004
select CONVERT(varchar(12) , getdate(), 107 )
09 12, 2004
select CONVERT(varchar(12) , getdate(), 108 )
11:06:08
select CONVERT(varchar(12) , getdate(), 109 )
09 12 2004 1
select CONVERT(varchar(12) , getdate(), 110 )
09-12-2004
select CONVERT(varchar(12) , getdate(), 113 )
12 09 2004 1
select CONVERT(varchar(12) , getdate(), 114 )
11:06:08.177
select getdate()
結(jié)果:2003-12-28 16:52:00.107
select convert(char(8),getdate(),112)
結(jié)果:20031228
select convert(char(8),getdate(),108)
結(jié)果:16:52:00
select convert(char(8),getdate(),112) 指日期格式
規(guī)則如下:
1 101 美國(guó) mm/dd/yyyy
2 102 ANSI yy.mm.dd
3 103 英國(guó)/法國(guó) dd/mm/yy
4 104 德國(guó) dd.mm.yy
5 105 意大利 dd-mm-yy
6 106 - dd mon yy
7 107 - mon dd, yy
8 108 - hh:mm:ss
- 9 或 109 (*) 默認(rèn)值 + 毫秒 mon dd yyyy hh:mi:ss:mmmAM(或 PM)
10 110 美國(guó) mm-dd-yy
11 111 日本 yy/mm/dd
12 112 ISO yymmdd
- 13 或 113 (*) 歐洲默認(rèn)值 + 毫秒 dd mon yyyy hh:mm:ss:mmm(24h)
14 114 - hh:mi:ss:mmm(24h)
- 20 或 120 (*) ODBC 規(guī)范 yyyy-mm-dd hh:mm:ss[.fff]
- 21 或 121 (*) ODBC 規(guī)范(帶毫秒) yyyy-mm-dd hh:mm:ss[.fff]
- 126(***) ISO8601 yyyy-mm-dd Thh:mm:ss:mmm(不含空格)
- 130* 科威特 dd mon yyyy hh:mi:ss:mmmAM
- 131* 科威特 dd/mm/yy hh:mi:ss:mmmAM
關(guān)于Emaker中字段的格式轉(zhuǎn)換和字段間的運(yùn)算代碼可以加到屬性里的“格式轉(zhuǎn)換(讀出)”和“格式轉(zhuǎn)換(寫入)”,table字段設(shè)定里的“字段”位置也可以靈活加函數(shù)。比如:'AF'+ID 或者ID+'/'+PWD ,convert(varchar(50),F1) ,
convert(int,%)-19110000 (讀出)
convert(char(8),convert(int,%)+19110000) (寫入)
實(shí)現(xiàn)行的合計(jì)運(yùn)算等等。加入:%系統(tǒng)變量%,則是調(diào)用在Emaker 系統(tǒng)中設(shè)定的系統(tǒng)變量。
版權(quán)聲明:本站文章來(lái)源標(biāo)注為YINGSOO的內(nèi)容版權(quán)均為本站所有,歡迎引用、轉(zhuǎn)載,請(qǐng)保持原文完整并注明來(lái)源及原文鏈接。禁止復(fù)制或仿造本網(wǎng)站,禁止在非www.sddonglingsh.com所屬的服務(wù)器上建立鏡像,否則將依法追究法律責(zé)任。本站部分內(nèi)容來(lái)源于網(wǎng)友推薦、互聯(lián)網(wǎng)收集整理而來(lái),僅供學(xué)習(xí)參考,不代表本站立場(chǎng),如有內(nèi)容涉嫌侵權(quán),請(qǐng)聯(lián)系alex-e#qq.com處理。
相關(guān)文章