GabrielVa
GabrielVa

Reputation: 2388

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 since the OrderDate. Can someone help out?

Thanks

Upvotes: 0

Views: 4448

Answers (1)

Oded
Oded

Reputation: 499002

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

Upvotes: 3

Related Questions