# Math calculation in IF Statement - Web Forms

659
2
08-11-2021 11:47 AM
New Contributor III

Hi,

I'm trying to set a date field based on an answer to an earlier question on my form.

So if the answer to the earlier question is "Yes" then, the date should be set it to 14 days from todays today.

To do this, I perform the following calculation on my date field.

``if(\${urgent_yesno} = 'Yes',today()+(14*24*60*60*1000),'')``

This works great in Desktop but does not work with the Web Forms. Is there something that I'm missing in the syntax? When I use just today() and omit the (14*24*60*60*1000), it sets the date okay. Seems to me it's the asthmatic that's messing up the statement.

I also tried the below. That also works with desktop but not the web form.

``if(selected(\${urgent_yesno},'Yes'), today() + 14*24*60*60*1000, '')``

Wondering if anyone can provide some guidance on this.

Thanks,

Ruchira

Tags (5)
1 Solution

Accepted Solutions
Esri Regular Contributor

The Survey123 web app only supports decimal time, while the field app supports both decimal time and epoch/UNIX time. To ensure your date/time calculations work in the web app, you must use decimal time.

The decimal-date-time() function will convert a date/time to decimal date/time. So your expression could look something like:

`if(\${urgent_yesno} = 'Yes', date(decimal-date-time(now()) + 14), '')`

Note the date() function is also used here, to treat the whole thing as a date/time object.

Please see the Dates and Time in Survey123 blog post and the Decimal date time documentation for more information.

Hope this helps! Best, Jim

2 Replies
Esri Regular Contributor

The Survey123 web app only supports decimal time, while the field app supports both decimal time and epoch/UNIX time. To ensure your date/time calculations work in the web app, you must use decimal time.

The decimal-date-time() function will convert a date/time to decimal date/time. So your expression could look something like:

`if(\${urgent_yesno} = 'Yes', date(decimal-date-time(now()) + 14), '')`

Note the date() function is also used here, to treat the whole thing as a date/time object.

Please see the Dates and Time in Survey123 blog post and the Decimal date time documentation for more information.

Hope this helps! Best, Jim

New Contributor III

Thanks for your help, Jim! That resolved my issues.