计算数据库中的两时间中间值
我数据库中存放两个时间段,一个开始时间,一个结束时间
begintime endtime
2012-05-01 2012-05-30
问下,我现在想要一个新字段,即为他们的中间时间,大不多也就是15号左右,请问怎么做
[解决办法]
if object_id('[tb]') is not null drop table [tb]gocreate table [tb]([begintime] datetime,[endtime] datetime)insert [tb]select '2012-05-01','2012-05-30'goalter table tb add midtime as dateadd(dd,datediff(dd,begintime,endtime)/2,begintime)goselect * from tb/**begintime endtime midtime----------------------- ----------------------- -----------------------2012-05-01 00:00:00.000 2012-05-30 00:00:00.000 2012-05-15 00:00:00.000(1 行受影响)**/