Subtract two time values in ms sql server 2008

Vyasdev Meledath picture Vyasdev Meledath · Oct 5, 2010 · Viewed 50k times · Source

How to subtract two time values in sql server 2008.I am using time variables in stored procedure.

please help

Answer

NullUserException picture NullUserException · Oct 5, 2010

You can use DATEDIFF():

SELECT DATEDIFF(Day, startDate, endDate)
  FROM table

SELECT DATEDIFF(Second, date, GETDATE())
  FROM table