Help: capture only month and year, but not day

Hi all,

we would like to know if is possible to capture only month and year but not day from date date data type to calculate age (Many interviewees from the community do not- know the day, but they can remember the month and year). We were thinking of
including two fields {1. enter month; 2/ enter year) so that data entered is entered manually, but we think it will be difficult to calculate age if we take the second approach.

We will be grateful if you help us with this issue

Thanks

You will likely have to do that. there are no question types for just month and year. and, you are not likely to get an accurate age without the day the person was born unless you assume it's the first of the month or something like that and calculate based on that.

if you do not wish to ask for it, then you HAVE to assume it when you are doing a date difference check.

you can ask the two questions, assume that the day is 1, and use Date(yyyy-mm-01) to get a date data type, then do another calc like
int((today() - Date(yyyy-mm-01)) div 30.4) because when you subtract two dates you get an integer. you then divide that by 30.4 (Average number of days per month) and get an estimate in months. divide that by 12, and you get age in years.

Hi @Mazz,

Could you explain the following a bit further, especially the date function to get a date type as month and year will be captured from two questions (second approach).

  1. enter month
  2. enter year

Many thanks

You should still be able to get the age to the precision of one month, as @Mazz described. I'd store birth month and year as separate values, and you can even store day where it's known if that'd be helpful - you can always combine them later if needed.

For age calculations, you can get the current year with
format-date(today(), "%Y")
and the current month number with
format-date(today(), "%m")

Using those, you can then calculate age in years with something like:

if(current_month >= birth month,
   current_year - birth_year,
   current_year - birth_year - 1)

Or age in months like this:

(current_year - birth_year) * 12
+ (current_month - birth_month)

(This seems too simple to work, but if the current month is before the birth month, then you'll end up subtracting the difference from the multiple of 12)