Ayub
November 17, 2021, 7:48am
1
1. What is the problem? Be very detailed.
I am trying to subtract 12 months from current date in "calculate", however unsure of correct format.
2. What app or server are you using and on what device and operating system? Include version numbers.
ODK Collect, XLSForm
3. What you have you tried to fix the problem?
Have reviewed following for two dates subtraction:
Hi @ARIF_AZAD_KHAN
I haven't tested the forms, but looking at the definitions, the only differences between the two forms are that the following variables are readonly:
date_default_converted
week_duration
visit_is_applicable
For easier comparison, I'd suggest you use a consistent template.
At the moment only one of the versions has the constraint field.
I hope this helps!
Best,
Andrea
However, it is not exactly what I am looking for
Any help / guidance would be appreciated!
Hi @Ayub
I think you could try subtracting the number of days (365). Useful functions are here
Expressions in calculations, constraints, and relevants can contain operators and functions. Operators: Math operators:,,,, Explanation, Example,,,+, addition,${salary_income} + ${self_employed_inc...
I suggest you also check this post as it might have some relevant information
I find it easier to reason about the year and the month/day separately:
concat(int(format-date(today(), β%Yβ)) + (50-${age}), format-date(today(), β%m%dβ))
That would be the correct expression if the service was provided today. You probably need to use the service date both to calculate the age and the components of the expiration date.
To compute a date N weeks from now:
format-date(date(decimal-date-time(today())+(N * 7)), β%Y%m%dβ)
Same as above, you'll need to use the service date ratheβ¦
Best,
Andrea
1 Like
Ayub
November 17, 2021, 12:25pm
3
Thanks @Andrea_Martin , @LN post helped, for subtracting a month, I used a week instead i.e. minus 4 weeks / 28 days like below to subtract a month:
format-date(date(decimal-date-time(today())-(4 * 7)), β%b, %Yβ)
However, is there still anyway to minus a whole month through helper functions i.e. not going at days or weeks level?
Hi Ayub,
I guess you are already aware about this, but you can also directly enter the number of days you want to subtract (e.g. standard number of days per month (30.4), or 365.25 for year)
format-date(date(decimal-date-time(today())-30.4), β%b, %Yβ)
But I'm not sure if there a way to
2 Likes
Ayub
November 18, 2021, 5:28pm
5
Hi @Andrea_Martin ,
As suggested, I believe going with days is the best option then!
Thanks!
1 Like