Subtract a year or 12 months from current date i.e. today()

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:

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
https://docs.getodk.org/form-operators-functions/#converting-dates-and-time

I suggest you also check this post as it might have some relevant information

Best,
Andrea

1 Like

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

Hi @Andrea_Martin,

As suggested, I believe going with days is the best option then!

Thanks!

1 Like