Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 12-04-2013, 11:31 AM
rossjp rossjp is offline Use formula in "Age" field to calculate age Windows XP Use formula in "Age" field to calculate age Office 2007
Novice
Use formula in "Age" field to calculate age
 
Join Date: Dec 2013
Location: Collins, MS
Posts: 4
rossjp is on a distinguished road
Smile Use formula in "Age" field to calculate age

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?
Reply With Quote
  #2  
Old 12-04-2013, 01:07 PM
macropod's Avatar
macropod macropod is offline Use formula in "Age" field to calculate age Windows 7 32bit Use formula in "Age" field to calculate age Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

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]
Reply With Quote
  #3  
Old 12-12-2013, 09:28 AM
rossjp rossjp is offline Use formula in "Age" field to calculate age Windows XP Use formula in "Age" field to calculate age Office 2007
Novice
Use formula in "Age" field to calculate age
 
Join Date: Dec 2013
Location: Collins, MS
Posts: 4
rossjp is on a distinguished road
Default

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.
Reply With Quote
  #4  
Old 12-12-2013, 02:14 PM
macropod's Avatar
macropod macropod is offline Use formula in "Age" field to calculate age Windows 7 32bit Use formula in "Age" field to calculate age Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

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]
Reply With Quote
  #5  
Old 12-13-2013, 07:20 AM
rossjp rossjp is offline Use formula in "Age" field to calculate age Windows XP Use formula in "Age" field to calculate age Office 2007
Novice
Use formula in "Age" field to calculate age
 
Join Date: Dec 2013
Location: Collins, MS
Posts: 4
rossjp is on a distinguished road
Default

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.
Reply With Quote
  #6  
Old 12-13-2013, 09:03 AM
Charles Kenyon Charles Kenyon is offline Use formula in "Age" field to calculate age Windows 7 64bit Use formula in "Age" field to calculate age Office 2013
Moderator
 
Join Date: Mar 2012
Location: Sun Prairie, Wisconsin
Posts: 9,082
Charles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant future
Default

Quote:
Originally Posted by rossjp View Post
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.
This looks like an Excel formula rather than a field calculation, to me. Field date math looks a lot more complex.

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
Reply With Quote
  #7  
Old 12-13-2013, 02:23 PM
macropod's Avatar
macropod macropod is offline Use formula in &quot;Age&quot; field to calculate age Windows 7 32bit Use formula in &quot;Age&quot; field to calculate age Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Quote:
Originally Posted by rossjp View Post
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.
As you'll see from Charles' reply and from the tutorial, it's a whole lot more complicated than that..
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #8  
Old 12-20-2013, 10:02 AM
rossjp rossjp is offline Use formula in &quot;Age&quot; field to calculate age Windows XP Use formula in &quot;Age&quot; field to calculate age Office 2007
Novice
Use formula in &quot;Age&quot; field to calculate age
 
Join Date: Dec 2013
Location: Collins, MS
Posts: 4
rossjp is on a distinguished road
Default

Thanks for the enlightenment regarding Word. I've gone back to good old reliable Excel for this.
Reply With Quote
  #9  
Old 12-20-2013, 03:48 PM
Charles Kenyon Charles Kenyon is offline Use formula in &quot;Age&quot; field to calculate age Windows 7 64bit Use formula in &quot;Age&quot; field to calculate age Office 2010 32bit
Moderator
 
Join Date: Mar 2012
Location: Sun Prairie, Wisconsin
Posts: 9,082
Charles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant future
Default

Quote:
Originally Posted by rossjp View Post
Thanks for the enlightenment regarding Word. I've gone back to good old reliable Excel for this.
Whatever works for you! Excel is built for calculations. Word is not.
Reply With Quote
  #10  
Old 12-30-2013, 12:31 AM
eNGiNe eNGiNe is offline Use formula in &quot;Age&quot; field to calculate age Windows 7 32bit Use formula in &quot;Age&quot; field to calculate age Office 2010 64bit
Expert
 
Join Date: Jan 2012
Location: Brussels [BE]
Posts: 746
eNGiNe is on a distinguished road
Default

Just for more options, try a search on "Epoch dates Excel" in case that throws up anything useful. I've not had to parse/compare dates for decades – or units of 315 360 000 seconds, if I've calculated that correctly <g> – but remember finding the arithmetic a lot easier when I wasn't working with ddmmyy strings.
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Use formula in &quot;Age&quot; field to calculate age Word options "field shading" reverts to "when selected" PaulBurcham Word 1 04-20-2013 11:18 AM
Use formula in &quot;Age&quot; field to calculate age 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
Use formula in &quot;Age&quot; field to calculate age 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

Other Forums: Access Forums

All times are GMT -7. The time now is 02:28 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft