?
Solved

Age Formula With Condition for No DOB Data

Posted on 2011-09-27
6
Medium Priority
?
466 Views
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

day(date(year({CRArrestees.ArrestedOn}),3,1)-1)=28

then

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})

else

// 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.
~Chopp
0
Comment
Question by:Chopp
[X]
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
6 Comments
 
LVL 101

Expert Comment

by:mlmcc
ID: 36714309
Try this

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

mlmcc
0
 

Author Comment

by:Chopp
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?


~Chopp
0
 
LVL 19

Accepted Solution

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

WhileReadingRecords;
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)  
    Else
        Year(Arrested) - Year(Birth) -1

HTH
0
[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

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

mlmcc
0
 
LVL 35

Expert Comment

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

 James
0
 

Author Closing Comment

by:Chopp
ID: 36719294
Thank you very much!
0

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