Make a field relevant based on a specified time period

02-23-2020 08:11 PM
New Contributor III

Hi there,

I am trying to make a field relevant based on a time calculation. I'm having a wee bit of trouble getting it to do exactly as I'd like, so I'm hoping someone may be able to take a look and give a few pointers? Many thanks in advance!...

I have surveyors collecting data during a specific time period, i.e. between 1am and 3am.
The field, Time_Warning (see image), is note type and is configured to act as a warning to the surveyor with the message - 'Warning - you are collecting outside of the survey period. This submission will not count. We assume this is a test.'.

The warning should be visible before the start epoch time, hidden during the survey period, and reappear after the end epoch time. If an entry is submitted outside of the survey period, the attribute is calculated as 'test', if its within the survey period the attribute remains null/blank. This is what I use for data QA during and post survey.

I can get the start epoch time to work - the field is visible before the start epoch time and disappears after. But once the time is post the survey period's end time, the field does not reappear as I expected it to.

My question is

- Is this functionality possible in Survey123? If it is, would someone mind taking a look at my calculations?
These are the calculations I'm using (in image)

now() + pulldata("@property", "utcoffset")*1000*60*60
((1582548600000) - (now() + (pulldata("@property", "utcoffset")*3600000)))>0 or ((1582464000000)-(now() + pulldata("@property", "utcoffset")))>0

if(((1582548600000) - (now() + (pulldata("@property", "utcoffset")*3600000)))>0 or ((1582464000000)-(now() + pulldata("@property", "utcoffset")))>0,'test','')

Start epoch time: 1582548600000
End epoch time:  1582464000000

(in milliseconds)

If it's not possible, then how this is currently working for me is good enough. Though it would be great if was in future Survey123 releases

Many thanks!

0 Kudos
3 Replies
Esri Esteemed Contributor

Hi Alannah,

I might suggest another approach- using the format-date() function to get the current hour on the device and compare that to your time window.  See the attached file

0 Kudos
New Contributor III

Hi James,

Thank you so much for pointing me in the right direction and sharing some examples.
After a few tweaks I got it working exactly how I want it!!!!!

What I did...

  • Hid the starttime field and moved now() to the calculate field.
  • Changed your Hour field calculate hour and minutes as a 4 digit number, %H%M – e.g. 1300
  • Added a Date field with format-date() function to calculate the date as an 8 digit number in YYYYMMDD format, %Y%m%d – e.g. 20200227 
  • Tweaked your note's relevant formula to include both date and time. The label text here is used to warn surveyors. If they are collecting within the survey period they won't see it.
  • Added TimeWarning field to record if the entry is in or out of the survey period. It's hidden from the surveyor. In calculate I am using the same relevant formula as above and I've changed false to 'Ok' and true to 'Test' so that I can use those attributes to QA the data as it comes in and pre and post survey period. I could include this in the note field however I want the 'Ok'/'Test' text hidden from the surveyor...

It is working using both the Survey123 app and webform.

I've attached my solution if you're interested.

Here's a screenshot of what the results look like (data tab in I had the survey date set as 20200227 and time between 1545-1645.

Thanks again!!!

Update - 22/07/2020.

The time_warning and time_check formulas in the attached spreadsheet have stopped working. 

It give this syntax error:

SyntaxError: Unexpected token `' in expression: if((int( /StreetCount/Date_Test )>=20200804 and int( /StreetCount/Date_Test ) <=20200804) and (int( /StreetCount/Time_Test ) >= 0100 and int( /StreetCount/Time_Test ) <=0300) , 'OK', 'Test')

I've got it working again - I'm concatenating the date and time to a 12 digit integer and comparing it against my survey period (YYYYMMDDHHMM).


New formulas:


if(int(concat(${datetest},${hourtest}))>=202007221150 and int(concat(${datetest},${hourtest}))<=202007221215,false(), true())


if(int(concat(${datetest},${timetest}))>=202007221150 and int(concat(${datetest},${timetest}))<=202007221215,’OK’, ‘Test’)



0 Kudos
MVP Frequent Contributor

This worked for me.  It checks if more than 7 days out.

${CalibrationDate}<date(decimal-date-time(now()) -  7)

0 Kudos