狼愛上貍

          我胡漢三又回來了

          導航

          <2006年11月>
          2930311234
          567891011
          12131415161718
          19202122232425
          262728293012
          3456789

          統(tǒng)計

          常用鏈接

          留言簿(20)

          隨筆分類

          隨筆檔案

          hideto

          java友

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          SQL Server日期格式的轉換

          ?SQL Server中文版的默認的日期字段datetime格式是yyyy-mm-dd Thh:mm:ss.mmm

          例如:

          select getdate()

          2004-09-12 11:06:08.177

          這對于在要不同數(shù)據(jù)庫間轉移數(shù)據(jù)或者習慣oracle日期格式YYYY-MM-DD HH24:MI:SS的人多少有些不方便.

          我整理了一下SQL Server里面可能經(jīng)常會用到的日期格式轉換方法:

          舉例如下:

          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

          更多的及具體說明請參考SQL Server的聯(lián)機叢書.


          Trackback: http://fengyu.china.com/sqlserver_datefmt.htm

          posted on 2006-11-18 17:27 狼愛上貍 閱讀(227) 評論(0)  編輯  收藏 所屬分類: MSSQL

          主站蜘蛛池模板: 门头沟区| 鄂尔多斯市| 桐柏县| 阳朔县| 婺源县| 湟中县| 资兴市| 盐山县| 张掖市| 集安市| 佛坪县| 都昌县| 井冈山市| 孝感市| 京山县| 星子县| 招远市| 汝城县| 安西县| 博白县| 景洪市| 济源市| 砚山县| 桦南县| 龙门县| 宿州市| 黎川县| 墨脱县| 通化市| 时尚| 上栗县| 垫江县| 木兰县| 潮州市| 澜沧| 孟连| 洪江市| 利川市| 淮南市| 巩义市| 六枝特区|