本文介紹了在 SQL 查詢中減去日期時間的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
我有一個我正在嘗試編寫的 Sql 視圖,我希望能夠獲取我的 DateTime 字段(稱為 OrderDate),然后從當前時間中減去它(GetDate())以顯示它在自 OrderDate 起的天數.有人可以幫忙嗎?
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?
謝謝
推薦答案
我假設您正在使用 SQL Server,因為您提到了 T-SQL GETDATE()
函數.
I am assuming you are using SQL Server, since you mention the T-SQL GETDATE()
function.
要計算兩個日期之間的差異,請使用 DATEDIFF代碼>函數:
For calculations on differences between two date, use the DATEDIFF
function:
SELECT DATEDIFF(day, OrderDate, GETDATE())
FROM myTable
這篇關于在 SQL 查詢中減去日期時間的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!