如何从当前日期SQL查询中减去截止日期? [英] How to Minus due date from current date SQL Query?

查看:1127
本文介绍了如何从当前日期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[^]


这篇关于如何从当前日期SQL查询中减去截止日期?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆