数据库是这样存储的ut_rq16 (char) Length 162012030607:37:54
2012030607:38:38
2012030607:40:34
2012030607:41:10我想显示成
2012-03-06-07:37:54
该怎么样格式化?
我试了下联机丛书里边的格式
select top 30 convert(char(8),ghrq,120) + '-' + convert(char(8),ghrq,108) time, * from test order by ghrq asc 108 - hh:mm:ss
110 美国 mm-dd-yy
怎么查询出来的和联机格式不一样?
20120306-20120306
20120306-20120306
20120306-20120306
20120306-20120306
20120306-20120306
2012030607:38:38
2012030607:40:34
2012030607:41:10我想显示成
2012-03-06-07:37:54
该怎么样格式化?
我试了下联机丛书里边的格式
select top 30 convert(char(8),ghrq,120) + '-' + convert(char(8),ghrq,108) time, * from test order by ghrq asc 108 - hh:mm:ss
110 美国 mm-dd-yy
怎么查询出来的和联机格式不一样?
20120306-20120306
20120306-20120306
20120306-20120306
20120306-20120306
20120306-20120306
LEN('2012030607:37:54')-8),120) as [date]
date
2012-03-06 07:37:54.000
select substring('2012030607:37:54',1,8)也可以, 是不是设置 star 为0 更好点?
测试数据:
create table a
(
date varchar(20)
)
insert into a
select '2012030607:37:54'结果:
date
----------------------
2012-03-06 07:37:54(1 行受影响)
select substring(date,1,4)+'-'+substring(date,5,2)+'-'+substring(date,7,2)+' '+substring(date,9,8) as date
from a
结果
date
----------------------
2012-03-06 07:37:54(1 行受影响)
接着上面的
insert into tb values('2012030607:37:54')
insert into tb values('2012030607:38:38')
insert into tb values('2012030607:40:34')
insert into tb values('2012030607:41:10')
goselect left(col,4) + '-' + substring(col,5,2) + '-' + substring(col , 7,2) + ' ' + right(col,8) from tbdrop table tb/*
-----------------------------------
2012-03-06 07:37:54
2012-03-06 07:38:38
2012-03-06 07:40:34
2012-03-06 07:41:10(所影响的行数为 4 行)*/