Display date difference in MS Word field

serhio picture serhio · Apr 27, 2010 · Viewed 9.8k times · Source

I have an CV and would like to automatically update my age when opening. So, what formula should I insert in a MS Word field?

Something like:

{= {DATE} - {"01/01/1983"} }

Answer

dgeyz picture dgeyz · Mar 21, 2013

I tried but could not find in Word fields the equivalent of the Excel way to substract a daytime from another one (let’s say 05/18/1983 from today 03/21/2013) which is easy in Excel since a daytime (01/01/1900 in Excel 2013) has been chosen as the beginning and every other day since is calculated according to this reference, the shown details only being a way of representing this result (full date, month in figures or its full name, or even the simple number of Excel), which can be toggled by right clicking on the cell and choosing the category cell format (since 01/01/1900 is 1, then 05/18/1983 is 30454 (...and also 00/01/1900 is 0!)).

To answer the initial question, I suggest this writing:

{= {DATE  \@ "YYYY"} - my_year - 1*{=OR({={DATE  \@ "MM"} < my_month};{=AND({={DATE  \@ "MM"} = my_month};{={ DATE  \@ "dd"} < my_day})})}  \* MERGEFORMAT}

bearing in mind:

  1. that curly brackets {} are Word specifics symbols (not normal ‘letters’) and should be inserted by pressing CTRL+F9.
  2. 'my_year', 'my_month' (twice) and 'my_day': should be numbers
  3. this writing is quite short, and suggest only 4 changes (unfortunaletly the month twice), which would help preventing errors
  4. for the beginners, this writing says: today's year minus my_year, and substract one if either today's month value is lower than my_month or both is equal and today's day value is lower than my_day, so that we do not have added one year in excess.

The MERGEFORMAT option is useful to keep the correct format.

Also, for those who are not used to working with Word fields:

  • right clicking on the text inside curly brackets {} and choosing “Toggle Field Codes”, switches from the code itself (texte inside) or the result of the calculus of this code, but that may not be up to date (may be a previous result also the code has been changed).
  • to make sure the result are up to date, right click and choose “Update Field”.
  • and to make sure you open every field inside a master field, select the whole field (better select the whole line containing it), right click and choose “Toggle Field Codes” (otherwise, some fields that are badly coded or that may return a void expression, may not be seen and may affect the seeing result later on when not wanted).

That would do for 05/18/1983 (I changed 1st of January, which is 01/01 to 18th of avoid confusion):

{= {DATE  \@ "YYYY"} - 1983 - 1*{=OR({={DATE  \@ "MM"} < 05};{=AND({={DATE  \@ "MM"} = 05};{={ DATE  \@ "dd"} < 18})})}  \* MERGEFORMAT}