Subtracting Datetime in SQL query
I have a Sql view Im trying to write and I'd like to be able to take my DateTime Field (called OrderDate) and then subtract it from the current Time (GetDate()) to show me how long its been in days sinc开发者_Python百科e the OrderDate. Can someone help out?
Thanks
I am assuming you are using SQL Server, since you mention the T-SQL GETDATE()
function.
For calculations on differences between two date, use the DATEDIFF
function:
SELECT DATEDIFF(day, OrderDate, GETDATE())
FROM myTable
精彩评论