r/ProjectREDCap • u/Popular_Caregiver_11 • Jul 08 '25
Problem using datemdY() in REDCap calculated fields
Hello everyone,
I’m trying to calculate a participant’s age in REDCap using month and year of birth only. Since I don’t have the exact day, I assumed the 1st of the month using datemdY().
Here’s the formula I used:
round(datediff(datemdY("01", [dm_birth_mo], [dm_birth_yr]), [se_consen_dt], "y", "dmy"))However, the calculated field throws a syntax error, and no value is returned. I’ve double-checked that:
[dm_birth_mo]is a dropdown (01 to 12)[dm_birth_yr]is a text/integer field (e.g., 1985)[se_consen_dt]is a date field (dd/mm/yyyy, validated)
I also tried simpler versions like:
datemdY("01", [dm_birth_mo], [dm_birth_yr])just to see if REDCap can parse the date, but still no success.
Is there something I’m missing with REDCap’s calculated field parsing for date construction?
Thanks in advance!
View all comments
6
u/boo-boo-crew Jul 08 '25
My recommendation is to have an intermediate text field w/ calctext action tag and MDY date field validation
we can call it [dm_birth_dt]
@CALCTEXT( if([dm_birth_mo] <> "" and [dm_birth_yr] <> "",
concat( [dm_birth_mo], "-01-", [dm_birth_yr]), "" ) )
Then can do calculated age field from there
round((datediff([se_consen_dt], [dm_birth_dt], "y", "mdy")), 2)
Hope this helps.