Unchangeable time and date function

Hi Kobo users,

I am in the need of restriction of time function. I want a user not being able to edit the time. It means that the time function should attach automatically whenever a user reach the time question.

Could anyone help me with this issue?

Regards,

Hi @chanmony,

You could do it as outlined in the post discussed previously:

Have a great day!

Hello @chanmony
I am not sure if you can control that this is set when the question is reached, Even with now()., calculations fire on load of the form already.
Also when you re-edit the saved case the now() will change, except you use once( now() )… More hints here https://docs.getodk.org/form-logic/#calculations
It might help if you have a condition in your calculation, like if(${var} != “”, once(count()). This will fire when the first entry is made and no more change later.
Maybe @Kal_Lam can give more details.

To provide more support you should specify more exactly what you want to monitor.
An example for the above (form just opened)
Now01

And a screenshot from KoBoCollect showing the automatic update on re-edit (just opened)


See last 2 lines. (I was surprised that the references to the now values in the text in Collect are cut down to date and the field values to simple datetime… I am sorry to say, that we feel a bit tired of all these differences between KoBoCollect and Enketo/Preview, often not documented even.)

2 Likes

Thanks so much @Kal_Lam for your responses. It worked now.

1 Like

Thanks so much @wroos for your very detailed information along with the screenshot. I really appreciated for your help.

2 Likes

Thanks everyone for these posts. I have tried various combinations to get the time stamp at a particular time in filling out the form. My form is a short repeat loop, and I want to record each time the loop is complete.

  1. now() only calculates the time the form is opened (as @wroos found).
  2. once(now)) seems to work great for the repeats - thanks for this tip. However, the first instance is still recorded as the time that the form is opened, not at the end of that first repeat loop. So my first instance of the time stamp may be older than the datetime I enter when I start to fill out the form, if I have had the form open for a while.
  3. trying to use a trigger, as per the ODK form logic, did not work for me - I only ended up with a time stamp at the first entry, and nothing in subsequent entries.
  4. trying to combine the trigger with a calculate as shown in the logic also did not to work for me - perhaps my logic was wrong, although I followed the example given.
1 Like

Thanks for sharing, @taniak! Would you to share your test form for more testing, please?

The result for the 2. option might be related to the fact that Kobo initially creates one default repeat, as far as I now. It could be different when using a repeat_count (and a internal full grouping, with a relevant).

Hi @wroos. Here is a modified version of my form for point 2 in my original response. I deleted irrelevant stuff at the beginning, and just left in my repeat loop, where I calculate time at the end of every trap installation. If you open the form, but wait a few minutes before starting to fill it out, you will see that the first time stamp is prior to the datetime entry that you have to input.
Repeat Time Stamp.xlsx (11.7 KB)

Do you also want me to (try to!!) recreate the forms that gave me the odd responses (points 3 & 4)?

Hi @taniak
Yes, would be great, please. Perhaps, you might create a simple version covering all issues (1-4).
Maybe you can also explain what you want to achieve with the date/time question in your form.

In a calculation, now() updates on open and save, whereas once( now() ) stores only initially.

There is also a difference between today metadata variable and the function today(). The first (${today}) stores the first open date of a form and doesn’t change. So, you might need to use this or once( today() ) in your calculation.

Hi @wroos,
I have created a sample version using all possible combinations I can think of to calculate the time :slight_smile: . I then used the form to “install” a number of traps, and looked at the output. The various time calculations are not all identical, and I don’t always seem to get all fields calculated for all records I enter.

Repeat Time Stamp.xlsx (12.0 KB)

What I am trying to do is to record the time each time a trap is installed (i.e., either each time the GPS data are entered, or when a new record is added). I was confused by not getting the same results when using the different methodologies, and with the inconsistencies I was getting.

In the grand scheme of things, micro-seconds (if you fill out a number of repeats very quickly!) or the even a difference of minutes does not matter to my form/survey, but I am now trying to understand the logic of these various ways of calculating time via these various ways. I think that the now() and once(now()) calculations occur when a new entry is loaded, and the calculations using the triggers are occurring a bit later, when the trigger is in fact activated.

Many thanks for your time on this.
Tania

1 Like