计算字段不适用于日期 [英] Calculation fields not working with dates

查看:119
本文介绍了计算字段不适用于日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经看到了很多寻找解决方案的示例,所以我很确定这是可能的.

I have seen quite a lot of examples looking for a solution, so I'm pretty certain that this possible.

我有包含日期的自定义文档属性(正确定义为日期)
我想对它们进行操作:

I have Custom Document Properties (properly defined as date) containing dates,
and I want to make operations on them :

{={  DOCPROPERTY  DateFieldTest  }+1 \@"d MMMM YYYY"}
'toggle DOCPROPERTY Field
{=07/04/2016+1 \@"d MMMM YYYY"}
'toggle calculation field
1

我也尝试过:

{=DATE(YEAR({  DOCPROPERTY  DateFieldTest  }),MONTH({  DOCPROPERTY  DateFieldTest  }),DAY({  DOCPROPERTY  DateFieldTest  })+1) \@"d MMMM YYYY"}
'toggle DOCPROPERTY Field
{=DATE(YEAR(07/04/2016),MONTH(07/04/2016),DAY(07/04/2016)+1) \@"d MMMM YYYY"}
'toggle calculation field
!Syntaxe Error, (

我只是想从自定义文档属性(日期字段)中的日期获取第二天.

I'm just trying to get the next day, from the date in the Custom Document Property (Date Field).

但是我似乎无法解决这个问题,有什么建议吗?

But I can't seem to get this to work, any suggestions?

推荐答案

查尔斯·肯尼恩(Charles Kenyon)花了一些时间收集了很多人的作品,并将其发布在他的网站上:

Charles Kenyon has spent some time gather up the work of many people and made it available on his website: http://www.addbalance.com/word/datefields2.htm

使用日期进行计算的基本技巧是将它们分为您要尝试的日,月和年,但是使用了在Word字段中不起作用的VBA方法.确实,Word进行日期计算时没有任何智能",您必须做所有这一切.因此,简单的例子:

The underlying trick for calculating with dates is to break them down into day, month and year, which you're attempting, but using the VBA approach that doesn't work in Word fields. Indeed, Word has no "smarts" whatsoever when it comes to date calculation - you have to do it all. So, simple example:

theDate + 1 = { DocProperty theDate \@ "MMMM" } { = {DocProperty theDate \@ "dd" } + 1 }, { DocProperty theDate \@ "yyyy" }

这很好,直到您到达每月的最后一天为止.然后,您必须考虑如果在一年的最后一天该怎么办...

This is fine, until you hit the last day of the month. And then you have to consider what to do if it's the last day of the year...

这是非常复杂的,因此我将复制Charles站点中的信息:

This is very complex, so I'm just going to copy the information from Charles's site:

这真是令人头晕!以下是一个字段,该字段以常规的书面英语格式为您提供从文档创建之日起两周的日期:

Here's a head-spinner! What follows is a field that gives you the date two weeks from the day a document is created, in regular written English format:

  • 创建日期:2015年7月9日-所需字段结果= 2015年7月23日
  • 创建日期:2014年7月23日-期望的字段结果= 2014年8月6日
  • 创建日期:2014年12月20日-所需字段结果= 1月3日, 2015
  • 创建日期:2015年2月27日-所需字段结果= 3月 2015年12月12日
  • 创建日期:2016年2月27日-所需字段日期 结果= 2016年3月13日

  • Creation date: July 9, 2015 - desired field result = July 23, 2015
  • Creation date: July 23, 2014 - desired field result = August 6, 2014
  • Creation date: December 20, 2014 - desired field result = January 3, 2015
  • Creation date: February 27, 2015 - desired field result = March 12, 2015
  • Creation date: February 27, 2016 - desired field date result = March 13, 2016

{QUOTE"{SET" Delay" 14} {SET"DaysInMonth" {IF {CreateDate \ @"MM"}<> 2
{= ROUND(30.575 * {CreateDate \ @"MM"},0)- ROUND(30.575 * {= {CreateDate \ @"MM"} -1},0)} {IF {= MOD({CreateDate \ @"yy"},4}}> 0"28""29"}}} {SET"NextMonth" {IF {CreateDate \ @"MM"} = 12"1/97" "{= {CreateDate \ @" MM} + 1}/97}} {IF {= {REF"Delay"} + {CreateDate \ @"dd"}}< = {REF"DaysInMonth"} {CreateDate \ @"MMMM {= {REF" Delay} + {CreateDate \ @" dd}},yyyy"} {引用{NextMonth \ @"MMMM"} {= {REF"Delay"} + {CreateDate \ @"dd"}-{REF"DaysInMonth"}}, {IF {CreateDate \ @"MM"}<> 12 {CreateDate \ @"yyyy"} {CreateDate \ @"{= 1 + {CreateDate \ @" yyyy}#" xxxx}"}}}}}}}

{ QUOTE "{ SET " Delay" "14" } { SET "DaysInMonth" { IF { CreateDate \@ "MM" } <> 2
{ = ROUND(30.575*{ CreateDate \@ "MM" },0)- ROUND(30.575*{ = { CreateDate \@ "MM" } -1 },0) } { IF { = MOD( { CreateDate \@"yy" } , 4 ) } > 0 "28" "29" } } } { SET "NextMonth" { IF { CreateDate \@ "MM" } = 12 "1/97" "{ = { CreateDate \@ "MM" } + 1 }/97 } } { IF { = { REF "Delay" } + { CreateDate \@ "dd" } } <= { REF"DaysInMonth" } { CreateDate \@ "MMMM { = { REF "Delay" } + { CreateDate \@ "dd" } }, yyyy"}{ QUOTE { NextMonth \@ "MMMM" } { = { REF "Delay" } + { CreateDate \@ "dd" } - { REF"DaysInMonth" } }, { IF { CreateDate \@ "MM" } <> 12 { CreateDate \@ "yyyy" } { CreateDate \@ "{ = 1 + { CreateDate \@ "yyyy" } # "xxxx" }" } } } }" }

上方示例字段中的颜色(下图!)表示我尝试匹配字段定界符并显示字段嵌套.为了清楚起见,添加了换行符,并且不应将其作为实际字段的一部分.我添加了这些修改有助于说明该字段的外观.绿色显示的那些字段不包含任何嵌套字段,但可能包含对其他字段设置的书签值的引用.

这篇关于计算字段不适用于日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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