I have a table timings with 4 different time fields namely : intime, outtime, lunchout, lunchin. I’m trying to find total hours logged i.e ((outtime-intime) – (lunchin-lunchout). Which I can fin out successfully using :
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
I have another table called attendance with the following fields : fname, presenttime, date.
create attendance timings
(
fname varchar(max),
presenttime datetime,
date datetime
)
I need to insert into attendance:
fname: fname from timings
presenttime: time1 – the result of above listed query
date: current system date. (only date, not time, need to remove timestamp from getdate() function)
I first attempted to use the datediff function, and late concatenate the values, but I was getting incorrect results.
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'
Thanks
I ended up changing both the field’s datatypes to varchar
and used this:
The results are satisfactory for now.