日期:2014-05-17  浏览次数:20435 次

一日期格式字符串增加时间问题?
SQL code


create table MOVIE_PLAYHIS_INFO
(
  MOVIE_PLAYHIS_ID INT IDENTITY(1,2) not null,
  START_TIME       VARCHAR(255),
  END_TIME         VARCHAR(255),
  primary key (MOVIE_PLAYHIS_ID)
);

START_TIME 格式 ‘yyyy-mm-dd hh:mi:ss’24小时制

增加2分两秒 怎么写SQL

'2012-08-14 13:00:00'   更新为 '2012-08-14 13:02:02'



------解决方案--------------------
SQL code

create table MOVIE_PLAYHIS_INFO
(
  MOVIE_PLAYHIS_ID INT IDENTITY(1,2) not null,
  START_TIME       VARCHAR(255),
  END_TIME         VARCHAR(255),
  primary key (MOVIE_PLAYHIS_ID)
);

insert into MOVIE_PLAYHIS_INFO(START_TIME) select '2012-08-14 13:00:00'

select * from MOVIE_PLAYHIS_INFO
/*
MOVIE_PLAYHIS_ID START_TIME                     END_TIME
---------------- ------------------------------ ------------------------------
1                2012-08-14 13:00:00            NULL
*/

update MOVIE_PLAYHIS_INFO 
set START_TIME=convert(varchar(20),
dateadd(s,2,cast(START_TIME as datetime)),120)

select * from MOVIE_PLAYHIS_INFO
/*
MOVIE_PLAYHIS_ID START_TIME                     END_TIME
---------------- ------------------------------ ------------------------------
1                2012-08-14 13:00:02            NULL
*/