如何从交付日期SQL Query中减去今天的日期(当前日期)?

时间:2014-01-31 15:59:02

标签: sql-server-2008

我有一张包含当前日期和交货日期的表格。我想从当前日期减去截止日期,并且只想在dbtable

中保留剩余天数
SELECT clientId, 
       curentDate, 
       deliveryDate DATEDIFF(day,-(deliveryDate) CURRENT_TIMESTAMP) AS Days_Left
FROM  dbo.tblorder

e.g:

  • 今天约会12/1/2014
  • 投放日期20/1/2014
  • 天还剩[{1}}

1 个答案:

答案 0 :(得分:1)

您是否在the documentation查看有关如何使用DATEDIFF的示例?

SELECT clientId, currentDate, deliveryDate, 
  Days_Left = DATEDIFF(DAY, CURRENT_TIMESTAMP, deliveryDate) 
FROM dbo.tblorder;