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
I have 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, (
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 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.
来源:https://stackoverflow.com/questions/42116944/calculation-fields-not-working-with-dates