Click here to Skip to main content
15,910,083 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
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..!!!
Posted

Hello,

This is how I do it:

SQL
DECLARE @endTime   DATETIME = '18:00'
DECLARE @duration  DATETIME = '1:45'
SELECT CONVERT(TIME(0), ((@endTime - @duration)))



Valery.
 
Share this answer
 
try this (tested on 2008 R2):

SQL
declare @d1 datetime='2010-01-01 01:45';
declare @d2 datetime='2010-01-01 18:00';

SELECT CONVERT(varchar,datediff(MI, @d1, @d2)/60)
    +':'+ CONVERT(varchar, datediff(MI, @d1, @d2)-60*(datediff(MI, @d1, @d2)/60))
 
Share this answer
 
SQL
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))



this is what i want..!!!! i got it..!!! thanks for ur reply..!!!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900