Date of Birth Formula

Posted on 2005-05-09
Last Modified: 2008-02-01
Hi Experts,

Been trying Ken Hamadys age calculation formula...

I get an error?

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!!
Question by:paulo111
    LVL 100

    Accepted Solution

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

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

    LVL 1

    Assisted Solution

    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


    LVL 100

    Expert Comment

    Glad i could help


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Suggested Solutions

    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 …
    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…
    how to add IIS SMTP to handle application/Scanner relays into office 365.
    Here's a very brief overview of the methods PRTG Network Monitor ( offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

    779 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

    Need Help in Real-Time?

    Connect with top rated Experts

    12 Experts available now in Live!

    Get 1:1 Help Now