# Program rule for Age value type

**URL:** <https://community.dhis2.org/t/program-rule-for-age-value-type/5002>\
**Category:** Support - Assistance technique\
**Created:** [11 April 2018 09:59 UTC](https://community.dhis2.org/t/program-rule-for-age-value-type/5002 "2018-04-11T09:59:13Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![Edouard\_Lavaud](https://dhis2.b-cdn.net/letter_avatar_proxy/v4/letter/e/71e660/32.png) [@Edouard\_Lavaud](https://community.dhis2.org/u/Edouard_Lavaud)\
**Post date:** [11 April 2018 10:57 UTC](https://community.dhis2.org/t/program-rule-for-age-value-type/5002/2 "2018-04-11T10:57:57Z")

</div>

Hi Em Le Hong,

If I well understand:  
You capture the age at a different moment than you would like the  
program rule to be executed?

If no, program rule executed on the same stage as you capture the age:

&nbsp;&nbsp;To be checked (never used the age value type so far), but age should  
be an integer. So you could just do: #{age\_value\_type} \< 5

If yes, program rule executed later on a different program stage:

&nbsp;&nbsp;Well, first you would be better off taking a date rather than the  
age. The d2 functions you mentioned are only for comparing dates, but  
age is not a date.

&nbsp;&nbsp;If you really want to use the age type, you have to convert it first  
in a date following the DHIS2 date pattern: YYYY-MM-DD

&nbsp;&nbsp;For that, you need to choose how to approximate a date of birth. Will  
you use the first day of the year? the last day? the 30 of June? The  
day you collected the information?  
&nbsp;&nbsp;Then you have to use the diverse d2 functions to create your date of birth.

&nbsp;&nbsp;As an example, in an enrollment form of a program I calculate the  
date of birth automatically (note that the age here is just a value  
type integer, and here all the program rules are performed in the same  
event: the enrollment):

&nbsp;&nbsp;Program rule, priority 1, I calculate the age in days:  
&nbsp;&nbsp;&nbsp;&nbsp;A{Age at enrollment} \* 365.25  
&nbsp;&nbsp;Program rule, priority 2, I calculate the date of birth according to  
the day of data capture  
&nbsp;&nbsp;&nbsp;&nbsp;d2:addDays(V{enrollment\_date}, -#{Age at enrollment in days})  
&nbsp;&nbsp;Program rule, priority 3, I round the date of birth to the 15 of June  
&nbsp;&nbsp;&nbsp;&nbsp;d2:concatenate(d2:substring(#{Date of birth calculated}, 0, 4), '-06-15')

&nbsp;&nbsp;After that I obtain an approximate date of birth I can use in the d2  
date functions.

Best,

Edouard

> **···**
>
> 2018-04-11 11:59 UTC+02:00, Em Le Hong \<em.hispvietnam@gmail.com\>:
> 
> > Dear all,
> > 
> > I create a tracker data element value type: Age
> > 
> > For event program, I want to use program to check and show error if Age is  
> > under 5  
> > I tried 2 functions d2:yearsBetween; d2:daysBetween with the expression as  
> > below but it doesn't work:
> > 
> > d2:daysBetween(#{age\_value\_type}, V{event\_date})  
> > d2:yearsBetween(#{age\_value\_type}, V{event\_date})
> > 
> > I check the manual Table 21.13. Custom functions to use in a program rule  
> > expression  
> > [Home - DHIS2 Documentation](https://docs.dhis2.org/2.29/en/user/html/configure_program_rule.html#create_program_rule)  
> > and don't see any functions for Age value type.
> > 
> > I created a ticket on DHIS2 Jira [[DHIS2-3381] - Jira](https://jira.dhis2.org/browse/DHIS2-3381)
> > 
> > I'm really appreciated if anyone has experience on this can share.
> > 
> > Regards,
> > 
> > --  
> > \*Em Le Hong\*  
> > DHIS2 Implementation| \*HISP Vietnam \*  
> > em.hispvietnam@gmail.com | \*Skype:\* em.hispvietnam@gmail.com
> 
> --  
> \*Edouard Lavaud, \*
> 
> \*MSc in Health Policy, Planning & FinancingMEng in  
> TelecommunicationUniversity Diploma in ICT for Health\*  
> \*Email:\* edouard.lavaud@gmail.com  
> \*Mobile:\* 0033 6 7210 23 59

---

_[View the full topic](https://community.dhis2.org/t/program-rule-for-age-value-type/5002)._
