Results 1 to 7 of 7

Thread: Age Calculation

  1. #1
    New Lounger
    Join Date
    Mar 2009
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Your DateCalc info is awesome. It has saved me many hours of searching.

    I have used your code from "Interactively Calculate A Personís Age" in a form to show a person's age in years from a birth date.

    {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}}
    {Years}}

    If the BirthDate is left blank, how do I make the calculation field blank as well? Or 0 would work too...

    Thanks

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    Welcome to the Lounge!

    You could use

    {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}}
    {IF {Birthdate}="" "" "{Years}"}

    Remember, never type the field braces { } yourself, use Ctrl+F9 to insert them.

  3. #3
    New Lounger
    Join Date
    Mar 2009
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thank you for such a quick response. This worked until I tabbed past the BirthDate field, then the formula displayed 2009.


    [quote name='HansV' post='763131' date='03-Mar-2009 12:18']Welcome to the Lounge!

    You could use

    {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}}
    {IF {Birthdate}="" "" "{Years}"}

    Remember, never type the field braces { } yourself, use Ctrl+F9 to insert them.[/quote]

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    [quote name='TBLB04' post='763251' date='04-Mar-2009 04:23']Thank you for such a quick response. This worked until I tabbed past the BirthDate field, then the formula displayed 2009.[/quote]
    I hope that macropod can solve this for you.

  5. #5
    Super Moderator
    Join Date
    May 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    5,054
    Thanks
    2
    Thanked 417 Times in 346 Posts
    [quote name='TBLB04' post='763251' date='04-Mar-2009 14:23']Thank you for such a quick response. This worked until I tabbed past the BirthDate field, then the formula displayed 2009.[/quote]
    Hi TBLB04,

    The problem is that, if you've used the coding suggested by Hans, the IF test he added isn't testing the actual contents of the default formfield value.
    Instead of using:
    [pre]{IF{Birthdate}="" "" "{Years}"[/pre]
    Try:
    [pre]{IF{Birthdate}= " " "" "{Years}"}[/pre]
    (ie a space after the '=' and 5 spaces between the first pair of double quotes.
    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
    Thanks!

  7. #7
    New Lounger
    Join Date
    Mar 2009
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Works perfectly! Thank you.

    [quote name='macropod' post='763266' date='04-Mar-2009 03:57']Hi TBLB04,

    The problem is that, if you've used the coding suggested by Hans, the IF test he added isn't testing the actual contents of the default formfield value.
    Instead of using:
    [pre]{IF{Birthdate}="" "" "{Years}"[/pre]
    Try:
    [pre]{IF{Birthdate}= " " "" "{Years}"}[/pre]
    (ie a space after the '=' and 5 spaces between the first pair of double quotes.[/quote]

Posting Permissions

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