Tip

Retrieve date of birth given age in CLP

I was faced with this problem of using OPNQRYF to extract a list base on the person's age (i.e. Age must be greater or equal to 18). The file has a Date of Birth field. In order to soft-code this method, I need to get the date of birth (DOB) to compare with person's birth date. The quickest method to get the DOB without having to create a service program is to use the 8870 method. This method is used by genealogist in calculating DOB.

Because of the change from Julian to Gregorian calendar, this method will not work if DOB is between September 2, 1752 and September 14, 1752.

Substitute the yymmdd (e.g. 180000) below if you want the exact age. For example, 21 year 8 months 10 days will have a value of 210810.


 
  
        dcl        &Lilian    *dec     9               
             dcl        &Second    *char    8               
             dcl        &GregDt    *char   17               
             dcl        &Picture   *char    8   'YYYYMMDD'  
             dcl        &BirthDt   *char    8               
             dcl        &Dob       *dec     8               
             dcl        &DobYYYY   *dec     4               
             dcl        &DobMM     *dec     2               
             dcl        &DobDD     *dec     2               

/*--------------------------------------------------------*/
/*  Select only age 18 & above. Calculate Date of Birth   */
/*  using the 8870 method.                                */
/*                                                        */
/*  Today's date in yyyymmdd       20030122               */
/*  - 18 years old in yymmdd      -  180000               */
/*  -------------------------      --------               */
/*                                 19850122               */
/*  - 8870 (30 days length)       -    8870               */
/*  -------------------------      --------               */
/*                                 19841252               */
/*                                                        */
/*  Adjust if dd is > 30        dd = 52 - 30   = 22       */
/*                              mm = 12 + 1    = 01       */
/*                            yyyy = 1984 + 1  = 1985     */
/*                                                        */
/*  After date adjustment          19850122 is DOB        */
/*                                                        */
/*--------------------------------------------------------*/
             callprc    CEELOCT        (&Lilian            +
                                        &Second            + 
                                        &GregDt  )           
             callprc    CEEDATM        (&Second            + 
                                        &Picture           + 
                                        &BirthDt           + 
                                        *OMIT    )           
             chgvar     &Dob           &BirthDt              
             chgvar     &Dob           (&Dob - 180000 - 8870)
             chgvar     &BirthDt       &Dob                  
             If         (%sst(&BirthDt  7 2) > '30')       do
               chgvar     &DobYYYY       %sst(&BirthDt  1  4)
               chgvar     &DobMM         %sst(&BirthDt  5  2)
               chgvar     &DobDD         %sst(&BirthDt  7  2)
               chgvar     &DobDD         (&DobDD - 30)       
               chgvar     &DobMM         (&DobMM + 1)        
               if         (&DobMM > 12)                    do
                 chgvar     &DobMM         (&DobMM - 12)     
                 chgvar     &DobYYYY       (&DobYYYY + 1)    
               enddo                                         
               chgvar     %sst(&BirthDt  1  4)   &DobYYYY    
               chgvar     %sst(&BirthDt  5  2)   &DobMM      
               chgvar     %sst(&BirthDt  7  2)   &DobDD      
               chgvar     &Dob           &BirthDt            
             Enddo                                           

This was first published in January 2003

There are Comments. Add yours.

 
TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
Sort by: OldestNewest

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

Disclaimer: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.