Age Formula With Condition for No DOB Data

Posted on 2011-09-27
Medium Priority
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 101

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 2000 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

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

LVL 101

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: 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.

Question has a verified solution.

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

I hate sub reports and always consider them the last resort in any reporting solution.  The negative effect on performance and maintainability is just not worth the easy ride they give the report writer.  Nine times out of ten reporting requirements…
There have always been a lot of questions related to when Crystal Reports evaluates report components (such as formulas, summaries, cross-tabs, charts, to name a few examples). Crystal Reports uses a two-pass reporting process to provide greater …
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

650 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