CONVERT(varchar(10) , sfrq, 21 )  
我们经常出于某种目的需要使用各种各样的日期格式,当然我们可以使用字符串操作来构造各种日期格式,但是有现成的函数为什么不用呢?

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

例如:

select getdate()

2016-09-12 11:06:08.177

整理了一下SQL Server里面可能经常会用到的日期格式转换方法:

举例如下:

select CONVERT(varchar, getdate(), 120 )
2016-09-12 11:06:08 select replace(replace(replace(CONVERT(varchar, getdate(), 120 ),'-',''),' ',''),':','')
20160912110608 select CONVERT(varchar(12) , getdate(), 111 )
2016/09/12 select CONVERT(varchar(12) , getdate(), 112 )
20160912 select CONVERT(varchar(12) , getdate(), 102 )
2016.09.12 select CONVERT(varchar(12) , getdate(), 101 )
09/12/2016 select CONVERT(varchar(12) , getdate(), 103 )
12/09/2016 select CONVERT(varchar(12) , getdate(), 104 )
12.09.2016 select CONVERT(varchar(12) , getdate(), 105 )
12-09-2016 select CONVERT(varchar(12) , getdate(), 106 )
12 09 2016 select CONVERT(varchar(12) , getdate(), 107 )
09 12, 2016 select CONVERT(varchar(12) , getdate(), 108 )
11:06:08 select CONVERT(varchar(12) , getdate(), 109 )
09 12 2016 1 select CONVERT(varchar(12) , getdate(), 110 )
09-12-2016 select CONVERT(varchar(12) , getdate(), 113 )
12 09 2016 1 select CONVERT(varchar(12) , getdate(), 114 )
11:06:08.177

帮助文档中的信息

Without century (yy)

With century (yyyy)

Standard

Input/Output**

-

0 or 100 (*)

Default

mon dd yyyy hh:miAM (or PM)

1

101

USA

mm/dd/yy

2

102

ANSI

yy.mm.dd

3

103

British/French

dd/mm/yy

4

104

German

dd.mm.yy

5

105

Italian

dd-mm-yy

6

106

-

dd mon yy

7

107

-

Mon dd, yy

8

108

-

hh:mm:ss

-

9 or 109 (*)

Default + milliseconds

mon dd yyyy hh:mi:ss:mmmAM (or PM)

10

110

USA

mm-dd-yy

11

111

JAPAN

yy/mm/dd

12

112

ISO

yymmdd

-

13 or 113 (*)

Europe default + milliseconds

dd mon yyyy hh:mm:ss:mmm(24h)

14

114

-

hh:mi:ss:mmm(24h)

-

20 or 120 (*)

ODBC canonical

yyyy-mm-dd hh:mi:ss(24h)

-

21 or 121 (*)

ODBC canonical (with milliseconds)

yyyy-mm-dd hh:mi:ss.mmm(24h)

-

126(***)

ISO8601

yyyy-mm-dd Thh:mm:ss:mmm(no spaces)

-

130*

Kuwaiti

dd mon yyyy hh:mi:ss:mmmAM

-

131*

Kuwaiti

dd/mm/yy hh:mi:ss:mmmAM

【网络收集】Sql Server datetime 常用日期格式转换的更多相关文章

  1. SQL 将非标准日期格式转换成标准格式,进行条件判断

    a.JLDate为非标准日期格式: 例: 2011-8-28 0:00:000011-8-28 0:00:000111-8-4 0:00:00 select CONVERT(varchar(50),C ...

  2. Sql与C#中日期格式转换总结

    SQL中的转换方法: 一.将string转换为datetime,主要是使用Convert方法, 方法,Convert(datetime [ ( length ) ] , expression, [st ...

  3. Hive常用日期格式转换

    固定日期转换成时间戳 select unix_timestamp('2016-08-16','yyyy-MM-dd') --1471276800 select unix_timestamp('2016 ...

  4. hive 常用日期格式转换

    固定日期转换成时间戳select unix_timestamp('2016-08-16','yyyy-MM-dd') --1471276800select unix_timestamp('201608 ...

  5. SQL Server case when 日期字符串转换 多表查询 嵌套子查询

    select distinct stu.*, dbo.GetClassNameByStudentCode(stu.Code) as ClassName, dbo.GetCourseNameByStud ...

  6. SQL SERVER 字符串类型varchar格式转换成int类型进行排序

    日常数据分析过程中,经常会遇到排序的情况,有时会根据空字段表进行临时排序,转换数据类型 使用  ORDER BY CAST (<字段名> AS INT)  ASC 举例: SELECT I ...

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

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

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

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

  9. SQL Server 2008对日期时间类型的改进

    微软在备受多年的争议后,终于对日期时间数据类型开刀了,在新版的SQL Server 2008中一口气增加了4种新的日期时间数据类型,包括: Date:一个纯的日期数据类型. Time:一个纯的时间数据 ...

随机推荐

  1. 为什么 JavaScript 中基本数据类型拥有 toString 之类方法?

    在 JavaSctipt 启示录一书中,关于为什么 JS 中基本数据类型可以调用一堆对象方法.大意即指,当原始数据类型(boolean,Number.String)在调用方法时,JS 将会创建对象,以 ...

  2. cocos2d-x 1970毫秒数转时间

    转自:http://www.cocos2dev.com/?p=322 做网络游戏时,服务器的时间在本地显示的时候要转成本地时间,可以利用系统函数转化. ";//假如这是服务器的时间 ] = ...

  3. 【WebForm】Repeater 序列号 在翻页情况下自增

    asp.net Repeater控件分页时,序号列翻页重新从1开始计数问题的解决思路及方法: 一般情况下,使用 <%# Container.ItemIndex + 1% > 给序号列来自增 ...

  4. Codeforces Round #318 [RussianCodeCup Thanks-Round] (Div. 1) A. Bear and Poker 分解

    A. Bear and Poker Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/573/pro ...

  5. Codeforces Gym 100733A Shitália 计算几何

    ShitáliaTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/view.acti ...

  6. WPF UI布局之概述

    在线演示:http://v.youku.com/v_show/id_XNzA5NDk2Mjcy.html 清晰版视频+代码下载:http://115.com/lb/5lbeer0m9lad 一.简单介 ...

  7. 如何通过VIM把代码格式化后生成HTML网页代码

    本文转自http://wangxiaoyu.blog.51cto.com/922065/203471 需求及思路:演示需要,需要网站上嵌入一些代码,我的建议做法是根据代码文件,生成相应的HTML代码, ...

  8. LeetCode: Validata Binary Search Tree

    LeetCode: Validata Binary Search Tree Given a binary tree, determine if it is a valid binary search ...

  9. 如何在 PHP 中处理 Protocol Buffers 数据

    Protocol Buffers是谷歌定义的一种跨语言.跨平台.可扩展的数据传输及存储的协议,因为将字段协议分别放在传输两端,传输数据中只包含数据本身,不需要包含字段说明,所以传输数据量小,解析效率高 ...

  10. 线程NSThread的使用

    // // ZYThreadViewController.h // Thread // // Created by yejiong on 15/11/4. // Copyright © 2015年 z ...