Select to view content in your preferred language

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

1072
4
Jump to solution
01-11-2024 07:21 AM
LeslieO_Hare2
Emerging Contributor

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!!

typename

calculation

bind::Type  
dateTimeDateTime

now()

   
notedateTimePrevious'pulldata("@layer","getValue","attributes.DateTime","https://services2.arcgis.com/lIdP1KS6Ves6C693/arcgis/rest/services/service_85b98d8810d94245a64f30d3a... DESC", ${WhereClauseFacID})

decimal

  
noteDuration

(decimal-date-time(${dateTimePrevious}) - decimal-date-time(${DateTime}))

decimal  

 

0 Kudos
1 Solution

Accepted Solutions
abureaux
MVP Frequent 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:

abureaux_1-1705010175589.png

abureaux_2-1705010195722.png

 

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.:

abureaux_3-1705010261073.png

 

View solution in original post

4 Replies
abureaux
MVP Frequent 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:

abureaux_1-1705010175589.png

abureaux_2-1705010195722.png

 

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.:

abureaux_3-1705010261073.png

 

LeslieO_Hare2
Emerging Contributor

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

0 Kudos
SusanMathai
Occasional Contributor

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.

SusanMathai_3-1707631663579.png

 

 

 

 

0 Kudos
abureaux
MVP Frequent 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')

0 Kudos