溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

SQLserver中如何使用convert函數(shù)轉(zhuǎn)換日期格式

發(fā)布時(shí)間:2021-07-28 14:30:23 來源:億速云 閱讀:967 作者:Leah 欄目:數(shù)據(jù)庫

這篇文章給大家介紹SQLserver中如何使用convert函數(shù)轉(zhuǎn)換日期格式,內(nèi)容非常詳細(xì),感興趣的小伙伴們可以參考借鑒,希望對(duì)大家能有所幫助。

SQL Server中文版的默認(rèn)的日期字段datetime格式是yyyy-mm-dd Thh:mm:ss.mmm 例如: 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 美國 mm/dd/yyyy 2 102 ANSI yy.mm.dd 3 103 英國/法國 dd/mm/yy 4 104 德國 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 美國 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)變量。

關(guān)于SQLserver中如何使用convert函數(shù)轉(zhuǎn)換日期格式就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,可以學(xué)到更多知識(shí)。如果覺得文章不錯(cuò),可以把它分享出去讓更多的人看到。

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI