Math calculation in IF Statement - Web Forms

441
2
Jump to solution
08-11-2021 11:47 AM
RuchiraWelikala2
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

0 Kudos
1 Solution

Accepted Solutions
Jim-Moore
Esri Regular Contributor

Hi @RuchiraWelikala2 

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

View solution in original post

2 Replies
Jim-Moore
Esri Regular Contributor

Hi @RuchiraWelikala2 

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

RuchiraWelikala2
New Contributor III

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