I created a survey that has a time field. In the default, I have now(). Staff have began to start using the survey and they have asked me If I could possibly change the time so that it rounded to the nearest quarter. For instance, if the current time is 11:31, it would round the time to 11:30.
Hi Nickholai,
It's a bit easier to understand how to get the start of the 15 minute time that you are in, so I'll start with that. You can use the modulo function to find out how much over quarter hour you are, and then subtract that from the time:
${timeValue} - ${timeValue} mod (15*60*1000)
In this example, I'm calculating from another question's value; you could substitute with now().
Note that 15 minutes is
(15 minutes) * (60 seconds / minute) * (1000 milliseconds / seconds) = 900000ms
To round, we need to divide by 15 minutes to get where an increase of 1 to a number represents an increase of 15 minutes, round (so we find the nearest 15 minute increment), and then re-multiply by 15 minutes to get us back to out time units:
date(round(${timeValue} div (900000),0)*(900000))
Note that a date time question calculated this way will update as the source value changes; a time question does not (but is calculated when a form is loaded).
Also note that we will be bringing significant changes to how dates are handled and calculated in 2.2; expect a blog post in GeoNet highlighting this soon.
Hi James,
It would be great to be able to have the time spinner only show 0, or 15, or 30 or 45 as well. Is there a way to do that?
Hi Scott,
There currently isn't a way to do that; I can bring this back as a potential enhancement.
Is there a way to accomplish this using Decimal Date Time? Some of my survey users are using the web version of the survey so the rounding calculations do not work. For reference this is how I have written the calculation so far, but it seems to only round down 1 minute:
if(round(${date_time} div(0.0104166675),0)*0.0104166675>${date_time}, round(${date_time} div(0.0104166675),0)*(0.0104166675)-0.0104166675,round(${date_time} div(0.0104166675),0)*(0.0104166675))
@JamesTedrick Good Afternoon - it's been a good several years since this topic has been touched and the original post is exactly what I wish to do in my form. Right now, I have a dateTime field which needs to be changed to show date and nearest quarter hour. I have searched but have been unsuccessful in finding reference in how to accomplish this. I appreciate any help!
Hey James Tedrick related to that. I'm doing a test that works but I'm struggling with the calculation.
In my survey I have a select one time. The user need to select the time the start one activity and same with the finish activity. Need help figuring out the hour based on the difference from those hours.
Please let me know if it's possible.
Regards.
Hi Cesar,
What are you using as values in the select_one questions? That information is needed to know how to construct a formula.
Hi James.
I figure it out.
It's basically the Start Time and Finish time setting them up as a "select_one" on the type column and in the "bind::esri:fieldType" column putting as a "esriFieldTypeDate".
Then my formula for the hours is: round(int(${timefinish} - ${timestart}) div (1000*60)div(60),1)
Regards.