-1

我有两个属性,effect_date,next_effect_date。我必须以天计算这两个日期之间的差异。dql 查询是什么?请帮忙

4

1 回答 1

2

使用此查询dm_document和日期属性r_creation_date以及r_modify_date通用对象类型和属性:

select DATEDIFF(day, r_creation_date, r_modify_date)
from dm_document where r_object_id = '<set_id_here>'

当您指定对象类型名称时,我们可以调整此查询。DATEDIFF 函数的语法是DATEDIFF(date_part, date1, date2)

结果值取决于您的存储库下的数据库。从文档:

If the repository is using Oracle or DB2, the return value is a floating point number.
If the repository is using DB2, the server assumes 365 days per year and 30.42 days per month (the
mean number of days in a month). These assumptions can cause return values that differ from the
expected value. To illustrate, the following example, which asks for the number of days between
March 1, 1996 and Feb 1, 1996, returns 30.42 instead of 28:
DATEDIFF(day, date('03/01/1996 0:0:0'),
date('02/01/1996 0:0:0'))
If the repository is using MS SQL Server, the return value is an integer for all units except day. If you
specify day in the function, the return value is a floating point.
The MS SQL Server implementation round up if the difference is one half or greater of the specified
unit. The implementations round down if the difference is less than one half of the specified unit. To
illustrate, the following example, which asks for the difference between March 1, 1996 and July 1,
1996 expressed as years, returns 0 because the difference is only 4 months.
DATEDIFF(year,date('03/01/1996'),date('07/01/1996'))
于 2016-02-08T10:38:33.737 回答