SQL Server中文版的默认的日期字段datetime格式是yyyy-mm-dd Thh:mm:ss.mmm 
例如: 
select getdate()    2004-09-12 11:06:08.177 
整理了一下SQL Server里面可能经常会用到的日期格式转换方法: 
举例如下: 
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

Convert第三个参数,进行日期类型转化时的格式: 
  
    如Convert(Char(10),     GetDate(),     111)   
    
    101     美国     mm/dd/yyyy     
    102     ANSI     yy.mm.dd     
    103     英国/法国     dd/mm/yy     
    104     德国     dd.mm.yy     
    105     意大利     dd-mm-yy     
    106     -     dd     mon     yy     
    107     -     mon     dd,     yy     
    108     -     hh:mm:ss     
    109     (*)       默认值     +     毫秒     mon     dd     yyyy     hh:mi:ss:mmmAM(或     PM)     
    110     美国     mm-dd-yy     
    111     日本     yy/mm/dd     
    112     ISO     yymmdd     
    113     (*)       欧洲默认值     +     毫秒     dd     mon     yyyy     hh:mm:ss:mmm(24h)     
    114     -     hh:mi:ss:mmm(24h)     
    120     (*)       ODBC     规范     yyyy-mm-dd     hh:mm:ss[.fff]     
    121     (*)       ODBC     规范(带毫秒)     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

Sql Server 中一个非常强大的日期格式化函数
Select CONVERT(varchar(100), GETDATE(), 0): 05 16 2006 10:57AM
Select CONVERT(varchar(100), GETDATE(), 1): 05/16/06
Select CONVERT(varchar(100), GETDATE(), 2): 06.05.16
Select CONVERT(varchar(100), GETDATE(), 3): 16/05/06
Select CONVERT(varchar(100), GETDATE(), 4): 16.05.06
Select CONVERT(varchar(100), GETDATE(), 5): 16-05-06
Select CONVERT(varchar(100), GETDATE(), 6): 16 05 06
Select CONVERT(varchar(100), GETDATE(), 7): 05 16, 06
Select CONVERT(varchar(100), GETDATE(), 8): 10:57:46
Select CONVERT(varchar(100), GETDATE(), 9): 05 16 2006 10:57:46:827AM
Select CONVERT(varchar(100), GETDATE(), 10): 05-16-06
Select CONVERT(varchar(100), GETDATE(), 11): 06/05/16
Select CONVERT(varchar(100), GETDATE(), 12): 060516
Select CONVERT(varchar(100), GETDATE(), 13): 16 05 2006 10:57:46:937
Select CONVERT(varchar(100), GETDATE(), 14): 10:57:46:967
Select CONVERT(varchar(100), GETDATE(), 20): 2006-05-16 10:57:47
Select CONVERT(varchar(100), GETDATE(), 21): 2006-05-16 10:57:47.157
Select CONVERT(varchar(100), GETDATE(), 22): 05/16/06 10:57:47 AM
Select CONVERT(varchar(100), GETDATE(), 23): 2006-05-16
Select CONVERT(varchar(100), GETDATE(), 24): 10:57:47
Select CONVERT(varchar(100), GETDATE(), 25): 2006-05-16 10:57:47.250
Select CONVERT(varchar(100), GETDATE(), 100): 05 16 2006 10:57AM
Select CONVERT(varchar(100), GETDATE(), 101): 05/16/2006
Select CONVERT(varchar(100), GETDATE(), 102): 2006.05.16
Select CONVERT(varchar(100), GETDATE(), 103): 16/05/2006
Select CONVERT(varchar(100), GETDATE(), 104): 16.05.2006
Select CONVERT(varchar(100), GETDATE(), 105): 16-05-2006
Select CONVERT(varchar(100), GETDATE(), 106): 16 05 2006
Select CONVERT(varchar(100), GETDATE(), 107): 05 16, 2006
Select CONVERT(varchar(100), GETDATE(), 108): 10:57:49
Select CONVERT(varchar(100), GETDATE(), 109): 05 16 2006 10:57:49:437AM
Select CONVERT(varchar(100), GETDATE(), 110): 05-16-2006
Select CONVERT(varchar(100), GETDATE(), 111): 2006/05/16
Select CONVERT(varchar(100), GETDATE(), 112): 20060516
Select CONVERT(varchar(100), GETDATE(), 113): 16 05 2006 10:57:49:513
Select CONVERT(varchar(100), GETDATE(), 114): 10:57:49:547
Select CONVERT(varchar(100), GETDATE(), 120): 2006-05-16 10:57:49
Select CONVERT(varchar(100), GETDATE(), 121): 2006-05-16 10:57:49.700
Select CONVERT(varchar(100), GETDATE(), 126): 2006-05-16T10:57:49.827
Select CONVERT(varchar(100), GETDATE(), 130): 18 ???? ?????? 1427 10:57:49:907AM
Select CONVERT(varchar(100), GETDATE(), 131): 18/04/1427 10:57:49:920AM

常用:
Select CONVERT(varchar(100), GETDATE(), 24): 10:57:47
Select CONVERT(varchar(100), GETDATE(), 108): 10:57:49

Select CONVERT(varchar(100), GETDATE(), 12): 060516
Select CONVERT(varchar(100), GETDATE(), 23): 2006-05-16
select CONVERT(varchar(12) , getdate(), 112 ) :   20040912 
Select CONVERT(varchar(100), GETDATE(), 8): 10:57:46

SQL Server中的日期格式化的更多相关文章

  1. SQL Server 函数之日期格式化函数

    SQL Server 函数之日期格式化函数 高文龙关注0人评论612人阅读2017-09-23 13:47:07 SQL Server 函数之日期格式化函数 对于一些经常写SQL Server执行语句 ...

  2. sql server中的日期详解使用(convert)

    转自:http://blog.csdn.net/hehe520347/article/details/48496853 有个字段值例如2012-07-02 00:00:00.000 转化成 2012- ...

  3. sql server中的日期函数

    DATEADD   在向指定日期加上一段时间的基础上,返回新的 datetime 值. 语法           DATEADD ( datepart , number, date ) 参数 (1) ...

  4. java web系统中时间比sql server中的日期少2天的解决办法

    系统环境 jdk:1.7 数据库:sql server 2008 问题描述 升级1.7之后查询出来的日期就比数据库中的少2天,降回1.6版本的jdk就正常了. 问题原因及解决办法 国内网站有很多不靠谱 ...

  5. SQL Server中的日期,时间组合查询

    如图所示,Jdate和Jdate2是两个分开的字段,一个是date类型,存储日期,一个是time(0)类型,存储具体时间 现在有这样的要求,就是获得(Jdate和Jdate2组合起来的日期时间)在(当 ...

  6. 在SQL Server中 获取日期、日期格式转换

    --常用日期转换参数: PRINT CONVERT(varchar, getdate(), 120 ) 2016-07-20 16:09:01 PRINT replace(replace(replac ...

  7. Sql Server 中使用日期遍历

    一个存储过程小案例,内容如下: declare @dt datetime set @dt='2016-01-01' while (@dt<='2016-12-31') begin -- 转换字符 ...

  8. [转载]SQL语句中的日期计算

    1. 本月的第一天SELECT  DATEADD(mm,  DATEDIFF(mm,0,getdate()),  0) 2. 本月的最后一天SELECT  dateadd(ms,-3,DATEADD( ...

  9. Sql Server 中一个非常强大的日期格式化函数

    Sql Server 中一个非常强大的日期格式化函数Select CONVERT(varchar(100), GETDATE(), 0)-- 05 16 2006 10:57AMSelect CONV ...

随机推荐

  1. informix(懒得通用)

    1.create view  444(...)  as select ...from... 2.insert into select.......union  select     不支持 请分开写 ...

  2. Centos7安装图形界面

    安装好字符操作系统后,使用网络安装(网络安装比较简单,不需要配置yum文件): yum groupinstall "GNOME Desktop" -y startx centos7 ...

  3. python datetime模块

    该模块的时间有限时限:1 - 9999 dir(datetime)  from datetime import datetime, timedelta, timezone dt = datetime. ...

  4. Windows安装Scrapy遇坑解决办

    PS: Windows真心不适合开发.且行且珍惜.... 坑: error: Setup script exited with error: Microsoft Visual C++ 9.0 is r ...

  5. Codeforces Round #388 (Div. 2) A,B,C,D

    A. Bachgold Problem time limit per test 1 second memory limit per test 256 megabytes input standard ...

  6. fonts.googleapis.com 加载慢的解决方法

    把:fonts.googleapis.com 替换成 fonts.useso.com

  7. 关于margin的一些问题

    引 在平时处理样式的过程中,会出现各种问题.比如: 包含在父元素中的子元素设置了浮动,子元素高度变化的时候父元素的高度没有随着变化,就是没有被撑高,父元素仍然是原来设置的那个高度 包含在父元素中的子元 ...

  8. 易货Beta版本发布说明

    说明 由于前几天确实比较忙,所以没来得及写发布说明. 功能 我们在beta版本主要加入了以下几个功能: 一:增加了用户的发布界面 二:增加了用户的购买界面 三:使用下拉刷新取代了之前的handler后 ...

  9. 老王讲自制RPC框架.(四.序列化与反序列化)

    #(序列化) 在实际的框架中,真正影响效率的就是数据的传输方式,以及传输的准备,或者说是tcp与http,序列化.当然要想提高整个框架的效率,需要采用一种高效的序列化 框架比如流行的protostuf ...

  10. 事务管理(下) 配置spring事务管理的几种方式(声明式事务)

    配置spring事务管理的几种方式(声明式事务) 概要: Spring对编程式事务的支持与EJB有很大的区别.不像EJB和Java事务API(Java Transaction API, JTA)耦合在 ...