Hidden Values Example 2: Calculate Using a Date

A common calculation is to take the date of the Last Menstrual Period (LMP) and calculate the Estimated Date of Delivery (EDD).
In general terms, the way we do this is by taking the date of LMP and adding approximately 9 months to it.

In CommCare terms, we want to take the value of the question "Date of Last Menstrual Period" and add 274 days (9 months + 1 week) to it. The resulting date is the EDD!

Let's try it out!

The reason you have to write date first and then put the parentheses around the expression is that when you add an integer number to the question lmp, the result is by default stored as a string, not as a date. We have to "cast" it as a date by putting date first and then parentheses around the expression. Otherwise it will just look like a long number!

Great- we have a lot of resources for this and now that you understand the general principles, there are a lot you can do with the instructions on our Common Logic and Calculations page. If you can't figure it out using those resources, send a note to the commcare users group!

You can also use the same tools to write complex AND/OR statements for Display or Validation conditions


In the next part of the tutorial you will learn how to write an "if" statement.

Go to the next part