用户定义的函数,用于计算时间长度

时间:2013-03-04 21:30:46

标签: vba

我正在创建一个数据库,用于计算两个里程碑之间经过的时间长度。

[ID]    [Milestone] [MDate]     [Length of Time]
--------------------------------------------------------
  1    1        Jan 1, 2013 [If the following milestone is 2 and they have both the same ID;
                     Calculate Datediff of Jan 1, 2013 vs Feb 1, 2013] Ans: 1 month]

  1    2        Feb 1, 2013 [if no milestone that followed, end date should be date();                          Datediff= Feb 1, 2013 vs. Date()]

  2    1            Jan 15, 2013    [If the following milestone is 2 and they have both the same ID;
                     Calculate Datediff of Jan 15, 2013 vs Feb 1, 2013] Ans: 18 days]

  2    2        Feb 1, 2013 [If the following milestone is 3 and they have both the same ID;
                     Calculate Datediff of Feb 1, 2013 vs Feb 27, 2013] Ans: 12 days]

  2    3        Feb 27, 2013    if no milestone that followed, end date should be date();                           Datediff= Feb 27, 2013 vs. Date()]

表的设置是:

[ID] - Number; 
[Milestone] - Number; 
[Mdate]-Date; 
[Length of time] - calculated field in the query; should be with a user defined function

问题是我不能自动计算两者之间的时间长度。我需要我的数据库来感知当具有相同ID和里程碑编号的两个记录被更改时,前一个里程碑将使用以下里程碑的结束日期,否则如果结束日期之后没有任何内容是当前日期。

我需要一个自动计算时间长度的用户自定义函数。

0 个答案:

没有答案