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)
M2:
now() + pulldata("@property", "utcoffset")*1000*60*60
L3:
((1582548600000) - (now() + (pulldata("@property", "utcoffset")*3600000)))>0 or ((1582464000000)-(now() + pulldata("@property", "utcoffset")))>0
M3:
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!
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...
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 Survey123.com). 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:
Time_Warning
if(int(concat(${datetest},${hourtest}))>=202007221150 and int(concat(${datetest},${hourtest}))<=202007221215,false(), true())
Time_Check
if(int(concat(${datetest},${timetest}))>=202007221150 and int(concat(${datetest},${timetest}))<=202007221215,’OK’, ‘Test’)
Cheers.
This worked for me. It checks if more than 7 days out.
${CalibrationDate}<date(decimal-date-time(now()) - 7)