Age Formula With Condition for No DOB Data

Posted on 2011-09-27
Last Modified: 2012-05-12
Hello Experts,  
I am using the formula pasted below to calculate the age of a person.  Unfortunately, if no DOB data is entered for a person, the report will not print, etc.  Can you advise me of how to adjust the formula to handle the condition where no DOB is entered.  

// birthday feb 29 and current year is leap year

if month({CREntityDescriptors.DateOfBirth})=2 and day({CREntityDescriptors.DateOfBirth})=29 and



if date(year({CRArrestees.ArrestedOn}),month({CREntityDescriptors.DateOfBirth}),
day({CREntityDescriptors.DateOfBirth})- 1) > {CRArrestees.ArrestedOn}

then year({CRArrestees.ArrestedOn})-year({CREntityDescriptors.DateOfBirth})-1

else year({CRArrestees.ArrestedOn})-year({CREntityDescriptors.DateOfBirth})


// birthday not feb 29 or current year is a leap year

if date(year({CRArrestees.ArrestedOn}),month({CREntityDescriptors.DateOfBirth}),
day({CREntityDescriptors.DateOfBirth})) > {CRArrestees.ArrestedOn}

then year({CRArrestees.ArrestedOn})-year({CREntityDescriptors.DateOfBirth})-1

else year({CRArrestees.ArrestedOn})-year({CREntityDescriptors.DateOfBirth})

Thank you for any help.
Question by:Chopp
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 100

Expert Comment

ID: 36714309
Try this

If Not IsNull({CREntityDescriptors.DateOfBirth}) then
    your code
    default age


Author Comment

ID: 36714684
Thank you.
I tried this method, and I receive an error message that says,
'A month number must be between 1 and 12'.

Thank you for the idea.
Any other ideas, or an alternative age formula?

LVL 19

Accepted Solution

GJParker earned 500 total points
ID: 36715593
Here is a simpler formula that will give an accurate age and handle the missing dates

DateVar Birth := {CREntityDescriptors.DateOfBirth};
DateVar Arrested := {CRArrestees.ArrestedOn};

If Not IsNull({CREntityDescriptors.DateOfBirth}) Then                                  
    If (Month(Arrested) * 100) + Day(Arrested) >= (Month(Birth) *100) + Day(Birth) Then
        Year(Arrested) - Year(Birth)  
        Year(Arrested) - Year(Birth) -1

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

LVL 100

Expert Comment

ID: 36717410
WHere do you get the error?
If it is in the DATE(...) calculation then I suspect you may have some bad data

LVL 35

Expert Comment

ID: 36718478
The question is, if no DOB is entered, what value do you have in that field?  If it's null (no value), then mlmcc's suggestion should handle that, assuming that you don't have CR set to replace nulls with the default value.  If it's some other value, then we may need to know what that value is.


Author Closing Comment

ID: 36719294
Thank you very much!

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Crystal Reports: 5 Tests for Top Performance It is complete, your masterpiece report.  Not only does it meet your customer’s expectations, it blows them out the water, all they want is beautifully summarised and displayed in a myriad of ways. …
Hello everyone, Hope you find this as helpful as we did. We have on the company I work for an application built in Delphi V with Crystal Reports 8. We all know that Crystal & Delphi can be temperamental sometimes and the worst thing is, nearly…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question