台湾的一个数据库,记录的时间显示是
1 书本 2011/9/25 上午 12:00:00
2 bbb 2011/9/25 上午 12:00:00 可否改成这样显示 2011-9-25 0:00:00 是不是在哪个地方设置就行。
1 书本 2011/9/25 上午 12:00:00
2 bbb 2011/9/25 上午 12:00:00 可否改成这样显示 2011-9-25 0:00:00 是不是在哪个地方设置就行。
--在表里修改该字段的数据类型
如果是查询时显示的话 看一楼
-- Author :fredrickhu(小F,向高手学习)
-- Date :2011-09-23 15:24:06
-- Verstion:
-- Microsoft SQL Server 2008 R2 (RTM) - 10.50.1617.0 (Intel X86)
-- Apr 22 2011 11:57:00
-- Copyright (c) Microsoft Corporation
-- Enterprise Evaluation Edition on Windows NT 6.1 <X64> (Build 7600: ) (WOW64)
--
----------------------------------------------------------------
--> 测试数据:[tb]
if object_id('[tb]') is not null drop table [tb]
go
create table [tb]([id] int,[col] varchar(4),[col2] varchar(50))
insert [tb]
select 1,'书本','2011/9/25 上午 12:00:00' union all
select 2,'bbb','2011/9/25 上午 12:00:00'
--------------开始查询--------------------------
select
ID,COL,cast(REPLACE(col2,'上午','') as datetime)
from
tb
----ID COL
----------- ---- -----------------------
1 书本 2011-09-25 12:00:00.000
2 bbb 2011-09-25 12:00:00.000(2 行受影响)
------------结果----------------------------
/*
*/
-- Author :fredrickhu(小F,向高手学习)
-- Date :2011-09-23 15:24:06
-- Verstion:
-- Microsoft SQL Server 2008 R2 (RTM) - 10.50.1617.0 (Intel X86)
-- Apr 22 2011 11:57:00
-- Copyright (c) Microsoft Corporation
-- Enterprise Evaluation Edition on Windows NT 6.1 <X64> (Build 7600: ) (WOW64)
--
----------------------------------------------------------------
--> 测试数据:[tb]
if object_id('[tb]') is not null drop table [tb]
go
create table [tb]([id] int,[col] varchar(4),[col2] varchar(50))
insert [tb]
select 1,'书本','2011/9/25 上午 12:00:00' union all
select 2,'bbb','2011/9/25 上午 12:00:00'
--------------开始查询--------------------------
select
ID,COL,cast(convert(varchar(10),REPLACE(col2,'上午',''),120) as datetime)
from
tb
------------结果----------------------------
/* ID COL
----------- ---- -----------------------
1 书本 2011-09-25 00:00:00.000
2 bbb 2011-09-25 00:00:00.000(2 行受影响)
*/
我是指这个字段我本来设的就是datetime型,我每输入一条记录,表里面时间就这样显示2011/9/25 上午 12:00:00 。 我想要表里面的时间显示2011-09-25 00:00:00 ,而不是2011/9/25 上午 12:00:00
不是在数据输出时,再进行处理。
select convert(datetime,CONVERT(nvarchar(10),'2011/9/25 上午 12:00:00',20))
-----------------
(无列名)
2011-09-25 00:00:00.000