[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2163
  • Last Modified:

Date of Birth Formula

Hi Experts,

Been trying Ken Hamadys age calculation formula...

I get an error?

WhileReadingRecords;
DateVar Birth:= {sps_MIU_Ilkeston_crystal_template_data.child_dob};   // Replace this with your field for Date Of Birth
DateVar Ann := CurrentDate;  // Replace this with CurrentDate to get their age as of the time of the report
                                                            //or the date field of an event to get their age as of the time of that event.
if (Month(Ann) * 100) + Day (Ann) >=(Month(Birth) *100) + Day (Birth)  
then Year (Ann) - Year(Birth)  
else Year (Ann) - Year(Birth) -1

I get the error which prompts for a 'date is required here' in front of the {sps_MIU_Ilkeston_crystal_template_data.child_dob}
it is a datetime(8) in my sql sp!!
0
paulo111
Asked:
paulo111
  • 2
2 Solutions
 
mlmccCommented:
>>I get the error which prompts for a 'date is required here' in front of the {sps_MIU_Ilkeston_crystal_template_data.child_dob}
it is a datetime(8) in my sql sp!!
That is the problem.  A DateVar is not a DataTiem and Crystal doesn't do automatic conversions

Try
DateVar Birth:= Date({sps_MIU_Ilkeston_crystal_template_data.child_dob});  

mlmcc
0
 
davetheravesmithCommented:
Well, I don't know if this will help, but it's a bulletproof way of calculating age to whole numbers, I don't trust DATEDIFF you see...

if Month({Employees.Birth Date}) < Month(CurrentDate) or (Month({Employees.Birth Date}) = Month(CurrentDate) and Day({Employees.Birth Date}) <= Day(CurrentDate)) then Year(CurrentDate) - Year({Employees.Birth Date}) else (Year(CurrentDate) - Year({Employees.Birth Date}))-1

It's nothing to do with Crystal or any other software for that matter, it works if you check it on a blackboard nver mind with software.

Anyway, thought it might help

Regards

DAVE THE RAVE
0
 
mlmccCommented:
Glad i could help

mlmcc
0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now