Date of birth between two date

Hello
I have a question, how can I accept the dates of people who were born in 01-01-2005 and more ??

First, check which question type you want to use: Date or Text? Cases below, with date of birth question called dob and assumption: Only DOB after 1st Jan 2005 allowed, not earlier.

Date Question

dob>= new DateTime(2005,01,01)

Text Question

I would in 99% of the cases stick with Text Question Type and pattern “##/##/####” (assuming your date format is DD/MM/YYYY). It is faster from enumerator perspective and gives you more flexibility in case the day or month (or year, really) is unknown - as one e.g could enter 99/12/2008. However, you need to add some more Validation Conditions to ensure integrity.

Checking for Text Entry to be DOB after 1st Jan 2005:

   new DateTime( 
   Convert.ToInt32(dob.Substring(6,4)), /*Year*/
   Convert.ToInt32(dob.Substring(3,2)), /*Month*/
   Convert.ToInt32(dob.Substring(0,2)) /*Day*/
     )
    >=
   new DateTime(2005,01,01)

But again, you also should check that the day dob.Substring(0,2) is in valid ranges. Also if you allow for “99” for day/month you should account for that cases. But that is beyond this post.

Hope that helps
Best
Peter

3 Likes

Hello,

I want to set user to select date of birth example: 2017.11.01

which codes should use to calculate the age and show it, and where to write it;
either in variable expresss or in validation condition

Thanks