Get the next day, from the date in the Custom Document Property

745 Views Asked by At

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, (
1

There are 1 best solutions below

3
On BEST ANSWER

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.

enter image description here