![]() |
|
#1
|
|||
|
|||
|
In a word 2007 document that I use as a form Ihave a DOB field, A current date field and an Age field. I need a formula in the Age field to calculate a person's age based on the other two field dates. Any help appreciated?
|
|
#2
|
||||
|
||||
|
To see how to do this and just about everything else you might want to do with dates in Word, check out my Microsoft Word Date Calculation Tutorial in the 'Sticky' thread at the top of this forum: Microsoft Word Date Calculation Tutorial
In particular, look at the item titled Interactively Calculate A Person’s Age. Do read the document's introductory material.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
|
#3
|
|||
|
|||
|
I have tried =DateDiff("yyyy",DOB,ReviewDate)+Int(Format(DOB,"m mdd").Format(ReviewDate,"mmdd")) This formula was tried in a field identified as Age but did not return anything. DOB and ReviewDate are other fields in the document both identifies as such in their properties.
|
|
#4
|
||||
|
||||
|
Have you even read the tutorial? It contains nothing like the code you're trying to use. Aside from the fact Word doesn't have a DateDiff field function, your formula looks like something you've copied & pasted from Excel.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
|
#5
|
|||
|
|||
|
Yes but I must not be as sharp as I thought because I can't figure out exactly what to enter into the "Age" field as a formula to give me a person's age by subtracting the "DOB" field date from the CurrentDate" field.
|
|
#6
|
|||
|
|||
|
Quote:
The basic field, on page 11 of Paul's tutorial, is: {QUOTE{ASK BirthDate "What is the Birthdate?"}{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}}{Set Months{=MOD(12+mm-bm-(dd<bd),12) \# 0}}{Set Days{=MOD(md+dd-bd,md) \# 0}}{IF{={IF{={BirthDate \@ "dddd"}}= "!*" 0 1}+{IF{={BirthDate \@ "MMMM"}}= "!*" 0 1}+{IF{by}= "!*" 1 0}+{IF{BirthDate \@ yyyyMMdd}<{DATE \@ yyyyMMdd} 0 1}}= 0 "If your Date of Birth was {Birthdate \@ "d MMMM yyyy"}, then your age is {Years} Year{IF{Years}= 1 "" s}, {Months} Month{IF{Months}= 1 "" s} and {Days} Day{IF{Days}= 1 "" s}." "Data entry error!"}} That one uses an Ask field to query for the date. The next field looks for the birthdate in a bookmark and may be what you are looking for. {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}}{Set Months{=MOD(12+mm-bm-(dd<bd),12) \# 0}}{Set Days{=MOD(md+dd-bd,md) \# 0}}"Your age is {Years} Year{IF{Years}= 1 "" s}, {Months} Month{IF{Months}= 1 "" s} and {Days} Day{IF{Days}= 1 "" s}."} You can see these field by using the Alt-F9 toggle to display field codes. This isn't rocket science but seems a bit like alchemy because of the complexities of the calendar as well as the assumptions built into Word and Windows. These fields do not work for dates before January 1, 1901. Read the tutorial, including the introductory part. Paul's tutorial is the best explanation of this stuff that I know, anywhere. You won't find it in books, and I don't think you'll find it on the Microsoft site. Using Fields in Microsoft Word |
|
#7
|
||||
|
||||
|
Quote:
But there are other fields in the tutorial that show how to work with dates before January 1, 1901 and can be adapted to do the required age calculations for starting dates going back millennia - which even Excel can't do - plus Excel can't calculate dates before January 1, 1900 and miscalculates dates before 1 March 1900 because it wrongly treats that year as a leap year.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
|
#8
|
|||
|
|||
|
Thanks for the enlightenment regarding Word. I've gone back to good old reliable Excel for this.
|
|
#9
|
|||
|
|||
|
Quote:
I'm so thankful, but I have to let you aware that in the "Interactively Calculate A Person's Age", in the =MOD() function, there are some commas instead of semicolons
|
|
#10
|
||||
|
||||
|
Did you read the tutorial's introduction?
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
|
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
Word options "field shading" reverts to "when selected"
|
PaulBurcham | Word | 1 | 04-20-2013 11:18 AM |
How to choose a "List" for certain "Heading" from "Modify" tool?
|
Jamal NUMAN | Word | 2 | 07-03-2011 03:11 AM |
| Cannot see all recipients in "to" field in new mail message (Outlook 2007) | sinjinx | Outlook | 0 | 12-15-2010 08:13 AM |
office 2003 - "to" field problem in new email
|
bruce_hyman | Outlook | 2 | 10-25-2010 08:04 PM |
| merge field formatting problem with "text to be inserted before" | wissam | Mail Merge | 0 | 12-13-2009 12:50 AM |