Share via

Age calculation

Anonymous
2014-02-13T16:58:34+00:00

A friend used this to calculate the age in the red rectangle.

{QUOTE{SET by {BirthDate @ yyyy}}

{SET bm {BirthDate @ M}}

{SET bd {BirthDate @ d}}

{SET yy {DATE @ yyyy}}

{SET mm {DATE @ M}}

{SET dd {DATE @ d}}

{SET md{=IF((mm=2),28+(mm=2)*((MOD(yy,4)=0)+(MOD(yy,400)=0)-(MOD(yy,100)=0)),31-((mm=4)+(mm=6)+(mm=9)+(mm=11)))}}

{Set Years{=yy-by-(mm<bm)-(mm=bm)*(dd<bd) # 0}}

"The age is {Years} Year{IF{Years}= 1 "" s}."}

However, the value returned is 33 instead of 32 since the person will be officially 33 starting only on April.

How the coding can be modified to return 32 instead of 33?

Thanks,

Microsoft 365 and Office | Word | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

2 answers

Sort by: Most helpful
  1. Paul Edstein 82,861 Reputation points Volunteer Moderator
    2014-02-15T00:51:12+00:00

    Now also cross-posted at: http://www.msofficeforums.com/word/19770-age-calculation-date-dob-fields.html

    For cross-posting etiquette, please read: http://www.excelguru.ca/content.php?184

    The document in the cross-posted link shows you are not using the field coding you've posted here - you've seriously munged it! Plus, although your post here indicates the use of content controls, bizarrely, the actual document has formfields embedded in the content controls. Formfields and content controls should not be used in the same document, let alone one inside the other.

    Was this answer helpful?

    0 comments No comments
  2. Paul Edstein 82,861 Reputation points Volunteer Moderator
    2014-02-13T20:43:43+00:00

    The field code works fine for me - returns 32 years with your April 8, 1981 input. Are you sure you updated the field after changing the date?

    PS: You can delete:

    {SET md{=IF((mm=2),28+(mm=2)*((MOD(yy,4)=0)+(MOD(yy,400)=0)-(MOD(yy,100)=0)),31-((mm=4)+(mm=6)+(mm=9)+(mm=11)))}}

    as it's not needed unless you're extending the calculation to days & months.

    Was this answer helpful?

    0 comments No comments