Groups | Blog | Home
all groups > sql server odbc > january 2005 >

sql server odbc : Date Difference



muffin1975_1 NO[at]SPAM eskom.co.za
1/21/2005 3:01:53 PM
Hi
I'm new to this whole SQL thing(electrical technician, heavy current). I use
TOAD to write queries on our db.
Question is : How do I subtract 2 dates from each other & format the result
to HH:mm:ss in new collumn. I usually do this in MsExcell after extracting
the data.

Thanks in advance.

Sue Hoegemeier
1/26/2005 4:01:41 PM
The update statement for the new column would be something
like:
UPDATE YourTable
SET NewColumn =
RIGHT('00' + CAST(datediff(ss, datefield1, datefield2)
/3600 as varchar(10)), 2) + ':'
+ RIGHT ('00' + CAST(datediff(ss, datefield1, datefield2)
%3600/60 as varchar(2)),2) + ':'
+ RIGHT ('00' + CAST(datediff(ss, datefield1, datefield2)
%60 as varchar(2)),2)

-Sue

On Fri, 21 Jan 2005 15:01:53 +0200, muffin1975_1@eskom.co.za
[quoted text, click to view]
AddThis Social Bookmark Button