Hi
I am working on an xls form that will run in ODK.
I want to have the time as a decimal type, be in 24hrs format and limit the the range (one cannot enter a value > 24.59.) so as to avoid errors from the enumerators eg entering 17.1500, or 25.15 etc.
How do I go about this.

Hi @Beryl_Makori
Do you want to use the time widget and then convert the result to a decimal value or maybe you want to use the decimal widget for that and constraint entered values?

You could also split the hours and minutes into 2 integer questions and then perform a calculation to get the decimal value. hours_and_minutes.xlsx (9.5 KB)

+-------------+---------+------------------------------+----------+------------------+---------------+------------------------------+-------------------------------+------------+
| type | name | label | required | hint | constraint | constraint_message | calculation | appearance |
+-------------+---------+------------------------------+----------+------------------+---------------+------------------------------+-------------------------------+------------+
| begin_group | group_a | Time A | | | | | | field-list |
| integer | a_hrs | Hour of day | yes | (24 hour format) | .>=0 and .<24 | hours must be less than 24 | | |
| integer | a_min | Minutes of hour | yes | | .>=0 and .<60 | minutes must be less than 60 | | |
| calculate | a_time | | | | | | ${a_hrs} + ( ${a_min} div 60) | |
| end_group | | | | | | | | |
| note | show | You entered ${a_time} hours. | | | | | | |
+-------------+---------+------------------------------+----------+------------------+---------------+------------------------------+-------------------------------+------------+

@danbjoseph can i have the calculation code be such that the point is in 2 decimal places and it gives a value not more than 59 mins
using the solution you have provided above,the end result is giving the time eg as 13.98432986.

Why do you want the hours/minute separator to be a period dot? I think usually a colon is used. When using a decimal, I think it might be interpreted as hours and fractions of an hour? For example, 3.5 would be interpreted as 3 hours and 30 minutes.

If the second half is just the minutes of the hour, you don't need to divide by 60 in the calculation. To zero pad the minutes, you need to check if the length of the minutes is 1 and if yes, add a 0 on the front. hours_and_minutes_v2.xlsx (9.5 KB)

+-------------+-----------+---------------------------------+----------+---------------+------------------------------+-------------------------------------------------------------------------------------+------------+
| type | name | label | required | constraint | constraint_message | calculation | appearance |
+-------------+-----------+---------------------------------+----------+---------------+------------------------------+-------------------------------------------------------------------------------------+------------+
| begin_group | group_a | Time A | | | | | field-list |
| integer | a_hrs | Hour of day (24h format) | yes | .>=0 and .<24 | hours must be less than 24 | | |
| integer | a_min | Minutes of hour | yes | .>=0 and .<60 | minutes must be less than 60 | | |
| calculate | a_min_str | | | | | if(string-length(string(${a_min}))=1,concat('0',string(${a_min})),string(${a_min})) | |
| calculate | a_time | | | | | concat(${a_hrs},':',${a_min_str}) | |
| end_group | | | | | | | |
| note | show | You entered a time of ${a_time} | | | | | |
+-------------+-----------+---------------------------------+----------+---------------+------------------------------+-------------------------------------------------------------------------------------+------------+