Using Date of birth to restrict further capturing

1. What is the problem? Be very detailed. Failing to control further entry by using date of birth

2. What app or server are you using and on what device and operating system? Include version numbers.

3. What you have you tried to fix the problem?
Date Check.xlsx (36.3 KB)

4. What steps can we take to reproduce the problem?
Attempted to use int((today() - ${respondent_dob}) div 365)
5. Anything else we should know or have? If you have a test form or screenshots or logs, attach below. I want to use date of birth as a means of preventing further capturing of data if the respondent is below 15 years

Leap years and such make it challenging to calculate age. Can you ask the respondent's age and then use that answer to control the rest of the survey?

I've modified your survey to use the int((${doi} - ${respondent_dob}) div 365) to calculate the age. And you can see that it doesn't work sometimes if the month/day of the two dates are close.
age_check.xlsx (14.2 KB)




I played around and I think the following works? If there's a less complex way to do it, I'd be interested to know. The narrative logic below is what I tried to implement in age_from_dates.xlsx (9.0 KB).

if birth month < than current month  
  then age is current year - birth year
  else if birth month  > current month
      then age is current year - birth year - 1
      else if  birth day > current date (we now assume birth month = current month)
        then age is current year - birth year - 1
        else age is current year - birth year