Set automatic date (month)

HI all. I am creating a survey form and I want to set 3 questions with the automatic date (month). For 1st question is today [today()], and 2nd question is last month, and 3rd question is last two months. For instance: if 1st question is August 2022, so 2nd question will automatically appear in July 2022 and 3rd question is June 2022. How to set it?

Welcome @pincambo,
The format-date() function will provide the elements you need to develop your calculation. You can also add and substract from a date type variable with the decimal-date-time() function.
The date() function can convert a string (e.g. ‘2022-12- 31’ to a date type.

Be aware that today() is always updating on edit/save of a form (even on server edit later). If you want to avoid this you need to use once( today() ) or the metadata today (${today}).

All available date functions can be found here
ODK XForms Specification.
Other hints on date variables can be found in the Help Center article
Date and time question types — KoboToolbox documentation.

With the search function of this forum you can find many examples to for date calculations, e.g. Calculate number of days between 2 dates - #6 by Kal_Lam

2 Likes