开发者

Subtracting Datetime in SQL query

开发者 https://www.devze.com 2023-02-20 10:21 出处:网络
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 s

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
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号