I have a requirement
select (18.00-1.45) =16.55
but i want is 16.15 hrs
how to do this pls help me out..!!!
Hours calculation in sql
2 Answers
Know the answer? Post it. Somebody with the same question will find it here.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Jignesh TrivediRank #16 · 50.3K reputationPosted Feb 12, 2014, 6:06 PM EST
hi,
I think, we cannot achieve this in one line SQL
try
Declare @diff as float
declare @hh as int
declare @mm as int
select @diff =(DateDiff(mi,Cast('1:45' as time),Cast('18:00' as time)))/60.00
select @hh = cast(@diff as int)
select @mm = (@diff - @hh)*60
select Cast(@hh as varchar(3)) + ':' + cast(@mm as varchar(3))
hope this will help you.
pradeep kumar72 reputationPosted Feb 13, 2014, 8:50 PM EST
check my solution i've found:
select CAST((CAST(FLOOR(18.00) * 60 + FLOOR(100 * 18.00) % 100 AS INT)-CAST(FLOOR(1.45) * 60 + FLOOR(100 * 1.45) % 100 AS INT))/60 +
(CAST(FLOOR(18.00) * 60 + FLOOR(100 * 18.00) % 100 AS INT)-CAST(FLOOR(1.45) * 60 + FLOOR(100 * 1.45) % 100 AS INT))%60 *0.01 AS DECIMAL(5,2))