Author |
Topic |
sign_seventh
Yak Posting Veteran
66 Posts |
Posted - 2008-01-04 : 02:11:01
|
Hi,I need to compute the total interval time for this sample:RecordsIn | Out8:30AM | 4:45PM 1:00pm | 6:10pm2:00pm | 2:15pmi want to have a result of8:15:005:10:0000:15:00 minsthnk you for your help |
|
jezemine
Master Smack Fu Yak Hacker
2886 Posts |
Posted - 2008-01-04 : 02:15:43
|
what are the datatypes of the in/out columns? elsasoft.org |
|
|
sign_seventh
Yak Posting Veteran
66 Posts |
Posted - 2008-01-04 : 02:30:10
|
datetime |
|
|
jezemine
Master Smack Fu Yak Hacker
2886 Posts |
Posted - 2008-01-04 : 02:40:39
|
select datediff(minute, [in], [out]) from yourtablebtw, in and out are very poor choices of column names. "in" is a reserved word in sql. elsasoft.org |
|
|
sign_seventh
Yak Posting Veteran
66 Posts |
Posted - 2008-01-04 : 04:56:51
|
select datediff(minute, [in], [out]) from yourtable --- this will only give the results in minutes. if it s more than 60minutes how can i convert it to hours |
|
|
ditch
Master Smack Fu Yak Hacker
1466 Posts |
Posted - 2008-01-04 : 05:11:56
|
select RIGHT('00' + LTRIM(STR(datediff(second, [in], [out]) / 3600, 2)), 2) + ':' + RIGHT('00' + LTRIM(STR((datediff(second, [in], [out]) - ((datediff(second, [in], [out]) / 3600) * 3600)) / 60, 2)), 2) as Mins from yourtableDuane. |
|
|
georgev
Posting Yak Master
122 Posts |
Posted - 2008-01-04 : 06:00:51
|
quote: Originally posted by sign_seventh select datediff(minute, [in], [out]) from yourtable --- this will only give the results in minutes. if it s more than 60minutes how can i convert it to hours
You do it in the presentation layer. George<3Engaged! |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2008-01-04 : 08:13:25
|
quote: Originally posted by georgev
quote: Originally posted by sign_seventh select datediff(minute, [in], [out]) from yourtable --- this will only give the results in minutes. if it s more than 60minutes how can i convert it to hours
You do it in the presentation layer. George<3Engaged!
I see my echo MadhivananFailing to plan is Planning to fail |
|
|
Lamprey
Master Smack Fu Yak Hacker
4614 Posts |
Posted - 2008-01-04 : 11:57:15
|
had a couple minutes to kill before a meeting: DECLARE @T TABLE (InDate DATETIME, OutDate DATETIME)INSERT @TSELECT '8:30 AM', '4:45 PM'UNION ALL SELECT '1:00pm', '6:10pm'UNION ALL SELECT '2:00pm', '2:15pm'SELECT CASE WHEN DATEPART(HOUR, DATEADD(SECOND, DATEDIFF(SECOND, InDate, OutDate), 0)) = 0 THEN CONVERT(VARCHAR(8), DATEADD(SECOND, DATEDIFF(SECOND, InDate, OutDate), 0), 108) + ' mins' ELSE CONVERT(VARCHAR(8), DATEADD(SECOND, DATEDIFF(SECOND, InDate, OutDate), 0), 108) END FROM @T |
|
|
sign_seventh
Yak Posting Veteran
66 Posts |
Posted - 2008-01-08 : 21:42:53
|
thx so much for the help, i did another tricks.cast((DATEDIFF(minute, TimeIn, TimeOut)/60)as varchar(50))+':'+cast((DATEDIFF(minute, TimeIn, TimeOut)%60) as varchar(50))+':00' as Durationthnx again. |
|
|
|