sql修改日期的方法,在别人的博客里找到的,做为收藏
来源:互联网 发布:武汉少儿编程培训机构 编辑:程序博客网 时间:2024/05/22 09:03
RETURNS varchar(20) AS BEGIN DECLARE @result varchar(20) SELECT @result = replace(replace(replace(replace(replace(replace(@format,
'yyyy',
'20' + substring(CONVERT(char(8),
@date, 3), 7, 2)),
'MM',
substring(CONVERT(char(8),
@date, 3), 4, 2)), 'dd',
substring(CONVERT(char(8),
@date, 3), 1, 2)), 'hh',
substring(CONVERT(char(8),
@date, 8), 1, 2)),
'ii',
substring(CONVERT(char(8),
@date, 8), 4, 2)), 'ss',
substring(CONVERT(char(8),
@date, 8), 7, 2))
RETURN @result END
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
- sql修改日期的方法,在别人的博客里找到的,做为收藏
- 收藏别人的博客
- 收藏一些别人的博客
- 如何让别人在搜索引擎找到自己的博客
- 如何让别人在搜索引擎找到自己的博客
- 别人的收藏
- 别人收藏的
- 别人收藏的资源
- 收藏别人的推荐
- SEO--让别人通过搜索引擎找到你的博客
- JavaScript技巧(别人的博客网址收藏)
- JavaScript技巧(别人的博客网址收藏)
- 如何在CSDN转载别人的博客
- 关注别人CSDN博客的方法
- 利用别人的sql练习题进行修改
- 从别人博客里看来的一道题,暂存
- 找到变量里记录的方法
- 别人的子系统博客
- [NET]ASP.NET 2.0学习笔记—— Master Page
- Java实现HTTP文件下载
- 关于用javascript改变class所用的setAttribute()方法
- Java中的数据类型--转载哈
- 转贴的一个挺有意思的程序
- sql修改日期的方法,在别人的博客里找到的,做为收藏
- vb .net 发送mail(JMAIL)
- SPS Service Unavailable
- How can we live with loss — and could we truly live without it?
- 使用httpwebrequest发送数据到网站
- javascript打印,或浏览功能
- javascript 常用验证函数
- union all
- WEB.CONFIG