从自定义文档属性中的日期获取第二天 [英] Get the next day, from the date in the Custom Document Property

查看:38
本文介绍了从自定义文档属性中的日期获取第二天的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有包含日期​​的自定义文档属性(定义为日期).

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

{={ DOCPROPERTY DateFieldTest }+1 \@d MMMM YYYY"}'切换文档属性字段{=07/04/2016+1 \@d MMMM YYYY"}'切换计算字段1

我也试过:

{=DATE(YEAR({ DOCPROPERTY DateFieldTest }),MONTH({ DOCPROPERTY DateFieldTest }),DAY({ DOCPROPERTY DateFieldTest })+1) \@d MMMM YYYY"}'切换文档属性字段{=日期(YEAR(07/04/2016),MONTH(07/04/2016),DAY(07/04/2016)+1) \@d MMMM YYYY"}'切换计算字段!语法错误,(

解决方案

Charles Kenyon 花了一些时间收集了许多人的工作并将其发布在他的网站上:

I have Custom Document Properties (defined as date) containing dates.

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

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

I also tried:

{=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, (

解决方案

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

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...


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:

  • 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"}{ QUOTE { NextMonth \@ "MMMM" } { = { REF "Delay" } + { CreateDate \@ "dd" } - { REF"DaysInMonth" } }, { IF { CreateDate \@ "MM" } <> 12 { CreateDate \@ "yyyy" } { CreateDate \@ "{ = 1 + { CreateDate \@ "yyyy" } # "xxxx" }" } } } }" }

The colors in the sample field above (below in image!) represent my attempt to match field delimiters and show nesting of fields. Line breaks have been added for clarity and should not be a part of the actual field. I added these modifications help illustrate what the field looks like. Those fields shown in green contain no nested fields but may contain references to bookmark values set by other fields.

这篇关于从自定义文档属性中的日期获取第二天的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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