Select to view content in your preferred language

Calculate time between two date-times using a date formatted from a pulldata question

745
4
01-11-2024 07:21 AM
New Contributor II

Hi,

I would like to calculate the hours (in decimal time) between the current inspection date/time and the previous inspection date/time.  I am using the pulldata function to recall the last inspection date/time and the now() function to populate the date/time of the current inspection, but when I try to calculate the time between the two dates I get an validation error message.  I think (but really I'm just guessing) the pulldata function is inserting the previous date/time as a string in epoch time and I can't figure out what the calculation formula should be?  Below is a copy of my form.  Any help would be appreciated!!

 type name calculation bind::Type dateTime DateTime now() note dateTimePrevious 'pulldata("@layer","getValue","attributes.DateTime","https://services2.arcgis.com/lIdP1KS6Ves6C693/arcgis/rest/services/service_85b98d8810d94245a64f30d3a... DESC", \${WhereClauseFacID}) decimal note Duration (decimal-date-time(\${dateTimePrevious}) - decimal-date-time(\${DateTime})) decimal

Tags (3)
1 Solution

Accepted Solutions
by
MVP Regular Contributor

Have you tried putting the pulldata into a text field to see what format it's pulling? If you are pulling from a dateTime field and dumping that value into a dateTime field, I feel like it should work.

Regarding the time difference, I'm not sure I understand. Do you just want the number of hours between two dates? That is relatively simple:

You will want some type of rounding on this otherwise you will end up with a very small decimal due to the slight differences in time. E.g.:

4 Replies
by
MVP Regular Contributor

Have you tried putting the pulldata into a text field to see what format it's pulling? If you are pulling from a dateTime field and dumping that value into a dateTime field, I feel like it should work.

Regarding the time difference, I'm not sure I understand. Do you just want the number of hours between two dates? That is relatively simple:

You will want some type of rounding on this otherwise you will end up with a very small decimal due to the slight differences in time. E.g.:

New Contributor II

Thank you, that worked!  I previously changed the field type to DateTime, but I think I just had the calculation incorrect.

New Contributor III

How to capture time input format  hh:mm:ss. and do calculations in survey forms for example  start time as hh:mm:ss and End time as hh:mm:ss. then report the time difference in minutes and seconds in a text box. I was able to display the difference in minutes as follows.

by
MVP Regular Contributor

All dates and times in S123 are captures in as a Unix Time Stamp.

All calculations (e.g., determining difference between two dates/times) needs to be done in Unix Time.

Whatever is captured in a date or dateTime question will print out as a "human date" in Feature Reports automatically.

If you want to display a captured date/time somewhere else in S123 (such as the instance_name, or display the result of a calculate) you will need to use format-date() or format-time() first.

hh:mm:ss = format-time(\${your_question},'%H:%M:%S')