我有一个包含 4 个不同时间字段的表计时,即:intime、outtime、lunchout、lunchin。我正在尝试查找记录的总小时数,即((outtime-intime)-(lunchin-lunchout)。我可以使用以下方法成功找到:
select convert (varchar(10),((outtime_d - intime_a)-(lunchin_c - lunchout_b)),8) as time1 from timings where fname = 'abc'
create table timings
(
fname varchar(max),
fid varchar(30) PRIMARY KEY CLUSTERED,
intime_a datetime,
outtime_d datetime,
lunchout_b datetime,
lunchin_c datetime
)
insert into timings values('Abc','4C00A2C82A0C','4/23/2012 2:07:51 PM','4/23/2012 9:07:51 PM','4/23/2012 4:12:51 PM','4/23/2012 5:07:51 PM')
time1 = 06:05:00
我有另一个名为出席的表,其中包含以下字段:fname、presenttime、date。
create attendance timings
(
fname varchar(max),
presenttime datetime,
date datetime
)
我需要插入出席:
fname:来自计时的 fname
presenttime: time1 - 上面列出的查询的结果
日期:当前系统日期。(只有日期,不是时间,需要从 getdate() 函数中删除时间戳)
我首先尝试使用 datediff 函数,然后将值串联起来,但得到的结果不正确。
SELECT ROUND(cast((datediff(hh, outtime_d ,intime_a) / 60.0) as FLOAT),2) AS DiffHour from timings where fname = 'abc'
SELECT ROUND(cast((datediff(mi, outtime_d ,intime_a) / 60.0) as FLOAT),2) AS DiffMinute from timings where fname = 'abc'
SELECT ROUND(cast((datediff(ss, outtime_d ,intime_a) / 60.0) as FLOAT),2) AS DiffSec from timings where fname = 'abc'
谢谢