I have a table in sql server with two fields named 'start_time' and 'stop_time'. both fields have datatype set as 'datetime'. now I want to subtract the 'start_time' from 'stop_time'? I have tried datediff() fuction,but no use. I want the correct outpput of date as well as time . Need help as early as possible.
Total Answers and Comments: 5
Last Update: January 15, 2009 Asked by: mun25_khanna
RE: I have a table in sql server with two fields named 'start_time' and 'stop_time'. both fields have datatype set as 'datetime'. now I want to subtract the 'start_time' from 'stop_time'? I have tried datediff() fuction,but no use. I want the correct outp
Try this example:
declare @startdatetime datetime declare @stopdatetime datetime declare @diffdays int declare @diffhours int declare @diffmins int -- assumption is startdate < stopdate always SET @startdatetime '2008-06-01 00:00:00.00' SET @stopdatetime '2008-06-02 11:35:43.793'
SET @diffdays DATEDIFF(dd @startdatetime @stopdatetime) SET @diffhours (DATEDIFF(hh @startdatetime @stopdatetime) - @diffdays*24) SET @diffmins (DATEDIFF(mi @startdatetime @stopdatetime)- @diffhours*60-@diffdays*24*60)
RE: I have a table in sql server with two fields named 'start_time' and 'stop_time'. both fields have datatype set as 'datetime'. now I want to subtract the 'start_time' from 'stop_time'? I have tried datediff() fuction,but no use. I want the correct outp
select starttime stoptime datediff(day starttime stoptime) as newtime from date.try this...........