计算两个日期之间有多少个月来定义是6个月还是6个月以上
Calculate how many months between two dates to define it is 6 months or over 6 months
我有一个 Lotus Notes 数据库。在一个表单中有一个名为 "ServiceDate" 的字段和另一个名为 "ReadOrEdit".
的字段
"ServiceDate" 字段我需要存储在日期中所以我使用
@Date(@ThisValue)
正确存储日期。
场景如下
如果ServiceDate在6个月以内,ReadOrEdit字段会显示"Editable",如果ServiceDate超过6个月,ReadOrEdit字段会显示"ReadOnly"。那时,用户还没有定义确切的 6 个月,所以我假设六个月大致有 186 (31 * 6) 天。
在"ReadOrEdit"字段中,我输入了以下代码
SixMonths := 186;
date := @Now;
calculation := (@Date(date)-@Date(ServiceDate))/((60*60*24) + 1);
result := @If(calculation > SixMonths;"ReadOnly";"Editable");
@If(@IsError(result);"no result";result)
当我向用户提出这个方法时,用户拒绝了我的方法。用户认为我不应该用天来定义6个月,6个月应该用月来定义,比如今天是01/03/2017,6个月之前是01/09/2016。如果日期在 01/09/2016 到 01/03/2017 之间,ReadOrEdit 字段应显示 "Editable"。如果日期早于 01/09/2016,ReadOrEdit 字段应显示 "ReadOnly".
这 website 启发我在 ReadOrEdit 字段中使用 @Adjust。我使用以下代码尝试使用 @Adjust 查找 ServiceDate 之前 6 个月的日期。
sixMonths :=@Date(@Adjust(ServiceDate;0;-6;0;0;0;0));
@If(@IsError(sixMonths);"no result";sixMonths)
当我运行程序时,如果输入ServiceDate是01/03/2017,ReadOrEdit字段会显示01/09/2016。由于结果与用户要求相同,我认为我应该在程序中使用@Adjust。接下来我需要考虑的是如何计算今天和 ServiceDate
之间的月数
我在网上查了一下,关于计算两个日期之间的月份的资料不多。我认为代码可能与我建议的代码相似,所以我开始修改代码以满足用户要求。
这是代码
today :=@Now;
sixMonths :=@Date(@Adjust(ServiceDate;0;-6;0;0;0;0));
sixMonthDays := @Abs(@Integer(( @Date(Today) - @Date(ServiceDate) )));
calculation:=(@Date(today)-@Date(sixMonths));
result := @If(calculation > sixMonthDays;"ReadOnly";"Editable");
@If(@IsError(result);"no result";result)
当我运行程序时,我发现结果不正确。
这是我的尝试,结果只显示 "ReadOnly" 无论日期在 6 个月以内还是日期超过 6 个月。
如果输入ServiceDate是01/03/2017,则显示"ReadOnly"
如果输入ServiceDate是28/02/2017,则显示"ReadOnly"
如果输入ServiceDate是01/09/2016,则显示"ReadOnly"
如果输入ServiceDate是02/09/2016,则显示"ReadOnly"
如果输入ServiceDate是02/08/2016,则显示"ReadOnly"
如果我更改代码
result := @If(calculation > sixMonthDays;"ReadOnly";"Editable");
至
result := @If(calculation < sixMonthDays;"ReadOnly";"Editable");
结果还是不正确。
这是我的尝试,结果只显示 "Editable" 无论日期在 6 个月以内还是日期超过 6 个月。
如果输入ServiceDate是01/03/2017,则显示"Editable"
如果输入ServiceDate是28/02/2017,则显示"Editable"
如果输入ServiceDate是01/09/2016,则显示"Editable"
如果输入ServiceDate是02/09/2016,则显示"Editable"
如果输入ServiceDate是02/08/2016,则显示"Editable"
其实我觉得最后的结果应该是这样的
如果输入 ServiceDate 是 01/03/2017,"ReadOrEdit" 字段显示 "Editable"
如果输入 ServiceDate 是 28/02/2017,"ReadOrEdit" 字段显示 "Editable"
如果输入 ServiceDate 是 01/09/2016,"ReadOrEdit" 字段显示 "Editable"
如果输入 ServiceDate 是 02/09/2016,"ReadOrEdit" 字段显示 "ReadOnly"
如果输入 ServiceDate 是 02/08/2016,"ReadOrEdit" 字段显示 "ReadOnly"
我修改了代码,我认为代码中有错误,但我知道是哪一部分。我读了这个 post 但我不明白。
如果有人告诉我我的错误或让我知道如何计算两个日期(今天和服务日期)之间的月数,以便我可以设置它是可编辑还是只读,我将不胜感激。非常感谢。
据我了解,服务日期后六个月内可以编辑某些内容吗?
您可以直接比较日期。
@If(@Adjust(ServiceDate; 0; 6; 0; 0; 0; 0) >= @Today; "Editable"; "ReadOnly")
这假定 ServiceDate 是一个 date/time 值。
如果 ServiceDate 小于或恰好 6 个月前,这应该 return "Editable",否则如果 ServiceDate 超过 6 个月前,则 return "ReadOnly"。 @Today 类似于 @Now,只是它是一个没有时间的日期值。
我有一个 Lotus Notes 数据库。在一个表单中有一个名为 "ServiceDate" 的字段和另一个名为 "ReadOrEdit".
的字段"ServiceDate" 字段我需要存储在日期中所以我使用
@Date(@ThisValue)
正确存储日期。
场景如下
如果ServiceDate在6个月以内,ReadOrEdit字段会显示"Editable",如果ServiceDate超过6个月,ReadOrEdit字段会显示"ReadOnly"。那时,用户还没有定义确切的 6 个月,所以我假设六个月大致有 186 (31 * 6) 天。
在"ReadOrEdit"字段中,我输入了以下代码
SixMonths := 186;
date := @Now;
calculation := (@Date(date)-@Date(ServiceDate))/((60*60*24) + 1);
result := @If(calculation > SixMonths;"ReadOnly";"Editable");
@If(@IsError(result);"no result";result)
当我向用户提出这个方法时,用户拒绝了我的方法。用户认为我不应该用天来定义6个月,6个月应该用月来定义,比如今天是01/03/2017,6个月之前是01/09/2016。如果日期在 01/09/2016 到 01/03/2017 之间,ReadOrEdit 字段应显示 "Editable"。如果日期早于 01/09/2016,ReadOrEdit 字段应显示 "ReadOnly".
这 website 启发我在 ReadOrEdit 字段中使用 @Adjust。我使用以下代码尝试使用 @Adjust 查找 ServiceDate 之前 6 个月的日期。
sixMonths :=@Date(@Adjust(ServiceDate;0;-6;0;0;0;0));
@If(@IsError(sixMonths);"no result";sixMonths)
当我运行程序时,如果输入ServiceDate是01/03/2017,ReadOrEdit字段会显示01/09/2016。由于结果与用户要求相同,我认为我应该在程序中使用@Adjust。接下来我需要考虑的是如何计算今天和 ServiceDate
之间的月数我在网上查了一下,关于计算两个日期之间的月份的资料不多。我认为代码可能与我建议的代码相似,所以我开始修改代码以满足用户要求。
这是代码
today :=@Now;
sixMonths :=@Date(@Adjust(ServiceDate;0;-6;0;0;0;0));
sixMonthDays := @Abs(@Integer(( @Date(Today) - @Date(ServiceDate) )));
calculation:=(@Date(today)-@Date(sixMonths));
result := @If(calculation > sixMonthDays;"ReadOnly";"Editable");
@If(@IsError(result);"no result";result)
当我运行程序时,我发现结果不正确。
这是我的尝试,结果只显示 "ReadOnly" 无论日期在 6 个月以内还是日期超过 6 个月。
如果输入ServiceDate是01/03/2017,则显示"ReadOnly"
如果输入ServiceDate是28/02/2017,则显示"ReadOnly"
如果输入ServiceDate是01/09/2016,则显示"ReadOnly"
如果输入ServiceDate是02/09/2016,则显示"ReadOnly"
如果输入ServiceDate是02/08/2016,则显示"ReadOnly"
如果我更改代码
result := @If(calculation > sixMonthDays;"ReadOnly";"Editable");
至
result := @If(calculation < sixMonthDays;"ReadOnly";"Editable");
结果还是不正确。
这是我的尝试,结果只显示 "Editable" 无论日期在 6 个月以内还是日期超过 6 个月。
如果输入ServiceDate是01/03/2017,则显示"Editable"
如果输入ServiceDate是28/02/2017,则显示"Editable"
如果输入ServiceDate是01/09/2016,则显示"Editable"
如果输入ServiceDate是02/09/2016,则显示"Editable"
如果输入ServiceDate是02/08/2016,则显示"Editable"
其实我觉得最后的结果应该是这样的
如果输入 ServiceDate 是 01/03/2017,"ReadOrEdit" 字段显示 "Editable"
如果输入 ServiceDate 是 28/02/2017,"ReadOrEdit" 字段显示 "Editable"
如果输入 ServiceDate 是 01/09/2016,"ReadOrEdit" 字段显示 "Editable"
如果输入 ServiceDate 是 02/09/2016,"ReadOrEdit" 字段显示 "ReadOnly"
如果输入 ServiceDate 是 02/08/2016,"ReadOrEdit" 字段显示 "ReadOnly"
我修改了代码,我认为代码中有错误,但我知道是哪一部分。我读了这个 post 但我不明白。
如果有人告诉我我的错误或让我知道如何计算两个日期(今天和服务日期)之间的月数,以便我可以设置它是可编辑还是只读,我将不胜感激。非常感谢。
据我了解,服务日期后六个月内可以编辑某些内容吗?
您可以直接比较日期。
@If(@Adjust(ServiceDate; 0; 6; 0; 0; 0; 0) >= @Today; "Editable"; "ReadOnly")
这假定 ServiceDate 是一个 date/time 值。
如果 ServiceDate 小于或恰好 6 个月前,这应该 return "Editable",否则如果 ServiceDate 超过 6 个月前,则 return "ReadOnly"。 @Today 类似于 @Now,只是它是一个没有时间的日期值。