从自定义文档属性中的日期获取第二天

编程入门 行业动态 更新时间:2024-10-27 04:36:56
本文介绍了从自定义文档属性中的日期获取第二天的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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

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

{={ 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: www.addbalance/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.

更多推荐

从自定义文档属性中的日期获取第二天

本文发布于:2023-11-24 02:54:26,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1623712.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:第二天   自定义   属性   日期   文档

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!