Search code examples
sql-serversql-server-2008timesubtraction

Subtract two time values in SQL Server


How to subtract two time values in SQL Server 2008. I am using time variables in a stored procedure.

Please help.


Solution

  • You can use DATEDIFF():

    SELECT DATEDIFF(Day, startDate, endDate)
      FROM table
    
    SELECT DATEDIFF(Second, date, GETDATE())
      FROM table