How to use a field code in MS Word to calculate age?
I am not a programmer so please be gentle!
In an MS Word document I need to calculate age in years from birthdate.
I've done a lot of searching and seem to think this may work:
{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 Years{=yy-by-(mm<bm)-(mm=bm)*(dd<bd) \# 0}}
My problem is that the above seems to refer to a field code
and I have no idea how to work with this.
Please lend a guiding hand with step-by-step instructions
for how to use the field code and the steps above to calculate
the age in years from a birthdate.
Thanks so much!
Top Answer/Comment:
Cross-posted at MS Office Forums as well as in the Microsoft Answers Forum. Please read guidance for cross-posters and follow that guidance.
Here is the field I posted there, based on Paul Edstein's work. The full field is there which gives you Years, Months, and days, as well. The field is based on the current date, as is your original field. Refer to Paul's tutorial for one that lets you set both beginning and end dates.
{QUOTE
{SET sy{BirthDate \@ yyyy}}
{SET sm{BirthDate \@ M}}
{SET sd{BirthDate \@ d}}
{SET ey{Date \@ yyyy}}
{SET em{Date \@ M}}
{SET ed{Date \@ d}}
{SET md{=IF((em=2),28+(em=2)*((MOD(ey,4)=0)+(MOD(ey,400 )=0)-(MOD(ey,100)=0)),31-((em=4)+(em=6)+(em=9)+(em=11)))}}
{Set Years{=ey-sy-(em<sm)-(em=sm)*(ed<sd)}}
"{Years}"}
If you want to use complex fields, you must take the time to learn how to create and edit fields. It is not rocket science. Here is my article on the Microsoft website on Dealing with Fields in Microsoft Word.
상단 광고의 [X] 버튼을 누르면 내용이 보입니다