日期之间的差额为负值 [英] Negative value on difference between dates

查看:125
本文介绍了日期之间的差额为负值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我正在使用sql server2005.在选择查询中,日期之间会有所不同.但是对于某些Rowa,它给出-ve值.这个问题怎么解决?以下是-ve值的示例

DATEDIFF(day,contractexpirydate,entrydate)DaysLeftForContractExpiry

其中contractexpirydate = 01/06/2010
和入门日期= 2002年8月14日
结果:-2702

感谢

Hi everyone,

I am using sql server 2005. On select query I make difference between dates. But for some rowa it is giving -ve values. how this problem be solved? Below is the example for -ve value

DATEDIFF(day,contractexpirydate,entrydate) DaysLeftForContractExpiry

where contractexpirydate=01/06/2010
and entrydate = 08/14/2002
result : -2702

thanks

推荐答案

将值四舍五入. DATEDIFF的格式期望开始日期早于结束日期,因此您需要将其更改为:
Change the values round. The format of DATEDIFF expects the start date before the end date, so you need to change it to:
DATEDIFF(day, entrydate, contractexpirydate) DaysLeftForContractExpiry


DATEDIFF的语法为DATEDIFF ( datepart , startdate , enddate )
日期差计算为(enddate - startdate).

结果,您在上述查询中得到否定结果.
更改查询中两列的顺序以解决此问题.

如果您得到其他负值,则基本上意味着您的contractexpiredate小于您的输入日期,并且您的业务逻辑应适当地处理此类条件.
The syntax for DATEDIFF is DATEDIFF ( datepart , startdate , enddate )
where the date difference is calculated as (enddate - startdate).

As a result you are getting a negative result in the above query.
Change the order of the two columns in your query to fix this.

If you get other negative values, it basically means your contractexpiredate is less than your entrydate and your business logic should handle such conditions appropriately.


这篇关于日期之间的差额为负值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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