Date: Sat, 1 Oct 2022 22:47:16 -0400 (EDT) Message-ID: <853988011.23641.1664678836879@confluence> Subject: Exported From Confluence MIME-Version: 1.0 Content-Type: multipart/related; boundary="----=_Part_23640_237729788.1664678836879" ------=_Part_23640_237729788.1664678836879 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Content-Location: file:///C:/exported.html Hidden Values Tutorial Part 2: Calculations Using a Date

# Hidden Values Tutorial Part 2: Calculations Using a Date

## Hidden Values Example 2: Calculate Using = a Date

A common calculation is to take the date of the Last Menstrual Period (L= MP) 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 La= st Menstrual Period" and add 274 days (9 months + 1 week) to it. The result= ing date is the EDD!

Let's try it out!

• Create a new hidden value by clicking on the 'Add Question'=  followed by Hidden Value from the question tree.
• Change the Question ID to "edd"
• Click on "Edit" next to the Calculate Condition box
• Drag the question "Date of Last Menstrual Period"= over to the Expression Editor (Advanced) box unt= il you see the green check mark, and then release
• Write a "+" because we want to add something to this date
• Type "274." Your total expression should look like this: • At the beginning of the expression write date and then put = parentheses around the expression like this: The reason you have to write date first and then put the parentheses aro= und the expression is that when you add an integer number to the question l= mp, 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 e= xpression. Otherwise it will just look like a long number!

• Hit "Save" and you will be ready to go!

Awesome! I have a slightly different type of calculation= but I'm not sure how to do it...

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

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

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

Go to the next part