Page 1 of 2 12 LastLast
Results 1 to 15 of 21
  1. #1
    4 Star Lounger
    Join Date
    Oct 2003
    Location
    Guelph, Ontario, Canada
    Posts
    428
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Is it possible to calculate a person's age from their date of birth in Microsoft Word 2003?

    I know this can be done in Access and Excel, but can it be done in Word?

    Tom

  2. #2
    Super Moderator
    Join Date
    May 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    5,055
    Thanks
    2
    Thanked 417 Times in 346 Posts
    [quote name='THWatson' post='774944' date='13-May-2009 12:12']Is it possible to calculate a person's age from their date of birth in Microsoft Word 2003?

    I know this can be done in Access and Excel, but can it be done in Word?

    Tom[/quote]
    Hi Tom,

    To see how to do this and just about everything else you might want to do with dates in Word using field coding (not macros), check out my Word Date Calculation Tutorial in Post 249902. In particular, look at the item titled 'Interactively Calculate A Personís Age'. Do read the document's introductory material.

    It's also possible to do the same sort of thing with a macro.
    Cheers,

    Paul Edstein
    [MS MVP - Word]

  3. #3
    4 Star Lounger
    Join Date
    Oct 2003
    Location
    Guelph, Ontario, Canada
    Posts
    428
    Thanks
    0
    Thanked 0 Times in 0 Posts
    [quote name='macropod' post='774947' date='13-May-2009 03:05']Hi Tom,

    To see how to do this and just about everything else you might want to do with dates in Word using field coding (not macros), check out my Word Date Calculation Tutorial in Post 249902. In particular, look at the item titled 'Interactively Calculate A Personís Age'. Do read the document's introductory material.

    It's also possible to do the same sort of thing with a macro.[/quote]
    Macropod
    Thanks! I downloaded the file and will have a look at it.

    I'm not wild about using a Macro, because the of the potential intrusion by viruses.

    Tom

  4. #4
    4 Star Lounger
    Join Date
    Oct 2003
    Location
    Guelph, Ontario, Canada
    Posts
    428
    Thanks
    0
    Thanked 0 Times in 0 Posts
    An example of what I want to do is calculate the age, using the date of birth July 29, 1937, or 7/29/1937

    So I plugged in the following
    {QUOTE
    {ASK StartDate "What is the starting date, in dd/mm/yyyy format, please?" \d 13/05/2009"}}{ASK Delay "What is the number of days +/- offset?"}
    SET a{=INT((14-{ StartDate \@M})/12)}}
    {SET b{={StartDate \@} yyyy}+4800-a}} ... plus the rest of whatever is in the code

    All I end up getting is the following:

    If the starting date is Monday, 1 January 2001 and the offset is 0 day, then the new date is Tuesday, 6 January 2009.

    How do I fix this?

    Thanks.

    Tom

  5. #5
    Super Moderator
    Join Date
    May 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    5,055
    Thanks
    2
    Thanked 417 Times in 346 Posts
    [quote name='THWatson' post='775002' date='13-May-2009 23:00']An example of what I want to do is calculate the age, using the date of birth July 29, 1937, or 7/29/1937
    All I end up getting is the following:
    If the starting date is Monday, 1 January 2001 and the offset is 0 day, then the new date is Tuesday, 6 January 2009
    How do I fix this?

    Thanks.
    Tom[/quote]
    Hi Tom,

    That's not the field code I pointed you to! It looks like the code from 'Interactively Calculate A Past Or Future Date', to which you've added a default starting date of 13/05/2009. It's hardly surprising you didn't get the result you're after.

    All you need to do is to copy the *correct* field code into your document, select it and press F9. For the 'July 29, 1937' input, I get:
    If your Date of Birth was 29 July 1937, then your age is 71 Years, 9 Months and 15 Days.
    Cheers,

    Paul Edstein
    [MS MVP - Word]

  6. #6
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    That's obviously not the "Interactively Calculate A Personís Age" example.

    I have attached a sample document that has been set up for US date format.
    Attached Files Attached Files

  7. #7
    4 Star Lounger
    Join Date
    Oct 2003
    Location
    Guelph, Ontario, Canada
    Posts
    428
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks for the feedback.

    I apologize. Very sorry...I got on the wrong code.

    When I highlight the code and press F9 I get the Input Box, "What is the birth date?"
    I enter the birth date and press OK...then I'm back in the code.
    Next, I press <Alt>F9, I get If your Date of Birth was 29 July 1937, then your age is 71 Years, 9 Months and 15 Days.

    I guess that's the way it's supposed to work.

    I'm getting closer. What I need to do now is work with the code, so that I end up getting only the age part, i.e. 71 Years, 9 Months and 15 Days
    This works nicely for children. Probably for adults I will need to get only the years, i.e. 71 years

    Tom

  8. #8
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    You don't need to display field codes except if you want to edit them.
    Simply click in the field and press F9 to update it.

    I have attached a version that displays the age in years only.
    Attached Files Attached Files

  9. #9
    4 Star Lounger
    Join Date
    Oct 2003
    Location
    Guelph, Ontario, Canada
    Posts
    428
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Is there a way to make this conditional, so that...
    1. if a person is under the age of 3, the age will show as Years, Months, Days
    2. if a person is 3 years of age or older, the age will show as Years only

    Or does this have to be 2 separate scripts?

    Tom

  10. #10
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    If you study the field codes, you'll see that you can add an IF field to check the age. See the attached version.
    Attached Files Attached Files

  11. #11
    4 Star Lounger
    Join Date
    Oct 2003
    Location
    Guelph, Ontario, Canada
    Posts
    428
    Thanks
    0
    Thanked 0 Times in 0 Posts
    [quote name='HansV' post='775075' date='13-May-2009 19:23']If you study the field codes, you'll see that you can add an IF field to check the age. See the attached version.[/quote]
    This is looking really good.

    Is there a reason it won't accept a date of birth before 1900?
    Entering a value in 1899 gives a result of 2009 years.

    Tom

  12. #12
    4 Star Lounger
    Join Date
    Oct 2003
    Location
    Guelph, Ontario, Canada
    Posts
    428
    Thanks
    0
    Thanked 0 Times in 0 Posts
    [quote name='THWatson' post='775109' date='13-May-2009 21:38']This is looking really good.

    Is there a reason it won't accept a date of birth before 1900?
    Entering a value in 1899 gives a result of 2009 years.

    Tom[/quote]
    Actually, I should have said it won't accept a date prior to 1901. A date in 1900 also gives 2009 years.

    Tom

  13. #13
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    As macropod explains in his document, the field codes only work correctly for dates between January 1, 1901 and December 31, 4095. To make them work with dates outside this range, they need to be modified considerably. See the section "Working With Dates Before 1 Jan 1901 Or After 31 Dec 4095" in macropod's document.

  14. #14
    4 Star Lounger
    Join Date
    Oct 2003
    Location
    Guelph, Ontario, Canada
    Posts
    428
    Thanks
    0
    Thanked 0 Times in 0 Posts
    [quote name='HansV' post='775114' date='13-May-2009 21:56']As macropod explains in his document, the field codes only work correctly for dates between January 1, 1901 and December 31, 4095. To make them work with dates outside this range, they need to be modified considerably. See the section "Working With Dates Before 1 Jan 1901 Or After 31 Dec 4095" in macropod's document.[/quote]
    Missed that piece. It's not worth turning modification hoops to do it, as the need will be rare indeed.

    Tom

  15. #15
    Super Moderator
    Join Date
    May 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    5,055
    Thanks
    2
    Thanked 417 Times in 346 Posts
    [quote name='THWatson' post='775131' date='14-May-2009 12:18']Missed that piece. It's not worth turning modification hoops to do it, as the need will be rare indeed.

    Tom[/quote]
    Indeed! Just how many people do you need to work out the age for who were born before 1/1/1901?
    Cheers,

    Paul Edstein
    [MS MVP - Word]

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •