如何从当前日期SQL查询中减去截止日期?
问题描述:
我有一张表格,其中包含当前日期的截止日期和交货日期,并且只想在dbtable中保留剩余天数
i have a table that has curent date and delivery date i want to minus due date from current date and want to save only days left dereference in dbtable
SELECT clientId, curentDate, deliveryDate DATEDIFF(day,-(deliveryDate) CURRENT_TIMESTAMP) AS Days_Left
FROM dbo.tblorder
例如
今天日期12/1/2014
交货日期20/1/2014
days left 8
e.g
today date 12/1/2014
delivery date 20/1/2014
days left 8
答
你只需要使用 DATEDIFF
方法来获取您感兴趣的差异。
You just need to use the DATEDIFF
method to get the difference you're interested in.
SELECT DATEDIFF(day, current date, due date) AS Days_Left
使用datediff,如 datediff [ ^ ]
如果日期是字符串类型,需要转换他们到目前为止首先像这样到目前为止的字符串 [ ^ ]
use datediff like this datediff[^]
If the date is of string type, need to convert them to date first like this string to date[^]