Friday, February 24, 2012

Date Difference

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.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
wrote:

>Hi
>I'm new to this whole SQL thing(electrical technician, heavy current). I us
e
>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.
>

No comments:

Post a Comment