Record time in correct time zone

7461
14
Jump to solution
03-27-2019 10:18 AM
WhitneyWeber
Occasional Contributor

When collecting data via my Survey123 with a field type of dateTime and bind::esri:fieldType of esriFieldTypeDate, the time displays correctly, but is recorded 4 hours different (presumably UTC). How do I get the recorded data to reflect the correct time zone? Do I need to record it in a different field of type calculate with something like now().toLocaleString or now()+int(2400) (2400 because 60*4hours)? I would think this would be a common question, but can't find it anywhere.

Tags (2)
0 Kudos
1 Solution

Accepted Solutions
JamesTedrick
Esri Esteemed Contributor

Hi Whitney,

There are a couple of things to adjust:

- '@property' is a keyword and should not be changed.  As the UTC offset is a device setting, it doesn't need to refer to a question

- You need to perform a calculation with the UTC offset value to get the 'local' time.

See the attached example.

View solution in original post

14 Replies
JamesTedrick
Esri Esteemed Contributor

Hi Whitney,

ArcGIS Online stores datetime information as UTC timestamps - see Dates and Time in Survey123 for ArcGIS.  Web applications should automatically adjust the time to display in your time zone; some desktop applications like ArcGIS Pro do not.  Using Survey123 Connect, you can get the device's offset from UTC using the pulldata("@property", 'utcoffset') function, which could then calculate a 'local' time value.

WhitneyWeber
Occasional Contributor

James,

Thank you for the reply, but I must have something wrong in what I added because my survey is now stuck 'Publishing' in the first stage of 'Getting form information'.

I kept the original field - name:visit_date, type: dateTime, bind::esri:fieldType: esriFieldTypeDate

I added a field - name: visit_date_local, type: calculate, calculation: pulldata("@visit_date", 'utcoffset'), bind::esri:fieldType: esriFieldTypeDate

Did I misinterpret your instructions or am I just having bad luck with the publishing?

How do I get it to publish? Just delete the survey and build a new one from the spreadsheet?

Whitney

0 Kudos
WhitneyWeber
Occasional Contributor

Sorry, I forgot to mention that I have visit_date with a default value of now(). I did not repeat that in the visit_date_local field, assuming it pulls it from the visit_date field.

0 Kudos
JamesTedrick
Esri Esteemed Contributor

Hi Whitney,

Is this added field within a repeat? There's an issue with publishing when only a field is added to a repeat - I would suggest adding a field in the parent form to publish and then remove the extra field.

0 Kudos
WhitneyWeber
Occasional Contributor

James,

You nailed it on the repeat! And I got it to publish successfully as you indicated, but the time still is not recording in the correct time zone in the downloaded data. I even added a note field, in case the calculate field required a note field. So I now have the following:

name:visit_date, type: dateTime, default: now(), bind::esri:fieldType: esriFieldTypeDate

name: visit_date_calc, type: calculate, calculation: pulldata("@visit_date", 'utcoffset'), bind::esri:fieldType: esriFieldTypeDate

name: vist_date_note: type: note, calculation: ${visit_date_calc}, bind::esri:fieldType: esriFieldTypeDate

When I download the data, although there is data in the original field of visit_date (albeit the wrong time zone), no date is recorded in either visit_date_calc or visit_date_note, so presumably something is wrong with visit_date_calc. Is the literal string of 'utcoffset' wrong? Should I be entering something else there? And if this ever gets resolved, is there a way for the correct time zone to be reflected in the autopopulated CreationDate and EditDate fields?

Whitney

0 Kudos
JamesTedrick
Esri Esteemed Contributor

Hi Whitney,

There are a couple of things to adjust:

- '@property' is a keyword and should not be changed.  As the UTC offset is a device setting, it doesn't need to refer to a question

- You need to perform a calculation with the UTC offset value to get the 'local' time.

See the attached example.

WhitneyWeber
Occasional Contributor

Thanks so much, James! That was very helpful!

Is there anywhere that information regarding other keywords and device settings can be found? I didn't find these in the types worksheet of the survey spreadsheet and wonder what else I am missing that would be helpful.

0 Kudos
JamesTedrick
Esri Esteemed Contributor

These would not appear in the types worksheet as they aren't part of the XLSForm validation that is what that sheet is used for.  A full description of metadata that can be loaded in as form questions is at Prepopulate answers—Survey123 for ArcGIS | ArcGIS 

0 Kudos
TobyStewart2
New Contributor II

Hi James

Sorry to open an old post but I used the above in a survey and it all goes through Ok, except when I test the submission of the survey and I get the following error

"bigint is incompatible with datetime2"

Any suggestions?

0 Kudos